QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#245732 | #7689. Flipping Cards | none | WA | 0ms | 3784kb | C++14 | 2.0kb | 2023-11-10 10:46:55 | 2023-11-10 10:46:56 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+6;
#define ll long long
#define int long long
void solve()
{
int n;
cin>>n;
vector<ll>a(n+1),b(n+1),c(n+1),d(n+1);
for(int i=1;i<=n;i++)cin>>a[i],c[i]=i;
for(int i=1;i<=n;i++)cin>>b[i],d[i]=i;
int l=1,r=n,ans=0;
sort(c.begin()+1,c.end(),[=](auto x,auto y){
return a[x]<a[y];
});
while(l<=r){
int mid=(l+r)>>1;
auto check1=[=](int k)->bool{
int bl=0,br=0;
for(int i=1;i<k;i++){
if(a[i]>=a[k])bl++;
}
for(int i=k+1;i<=n;i++){
if(a[i]>=a[k])br++;
}
int sum=0,ans=0;
for(int i=1;i<k;i++){
int yl=(a[i]>=a[k]),now=(b[i]>=a[k]);
int num=now-yl;
if(sum<0)sum=0;
sum=sum+num;
ans=max(ans,sum);
}
int res=bl+br;
res=max(res,ans+bl+br);
sum=0,ans=0;
for(int i=k+1;i<=n;i++){
int yl=(a[i]>=a[k]),now=(b[i]>=a[k]);
int num=now-yl;
if(sum<0)sum=0;
sum=sum+num;
ans=max(ans,sum);
}
res=max(res,ans+bl+br);
//cout<<ans<<" "<<bl<<" "<<br<<" "<<k<<endl;
if(res>=n/2)return true;
return false;
};
if(check1(c[mid]))ans=mid,l=mid+1;
else r=mid-1;
}
ll res=0;
//cout<<c[ans]<<endl;
res=a[c[ans]];
sort(c.begin()+1,c.end(),[=](auto x,auto y){
return b[x]<b[y];
});
l=1,r=n,ans=0;
while(l<=r){
int mid=(l+r)>>1;
auto check2=[=](int k)->bool{
int ans=0;
for(int i=1;i<=n;i++){
if(a[i]>=b[k]&&i!=k)ans++;
}
int ansl=0,ansr=0,sum=0;
for(int i=k+1;i<=n;i++){
int yl=(a[i]>=b[k]),now=(b[i]>=b[k]);
int num=now-yl;
sum+=num;
ansr=max(ansr,sum);
}
sum=0;
for(int i=k-1;i>=1;i--){
int yl=(a[i]>=b[k]),now=(b[i]>=b[k]);
int num=now-yl;
sum+=num;
ansl=max(ansl,sum);
}
if(ans+ansl+ansr>=n/2)return true;
return false;
};
if(check2(c[mid]))ans=mid,l=mid+1;
else r=mid-1;
}
res=max(res,b[c[ans]]);
cout<<res<<endl;
}
signed main(){
ios::sync_with_stdio(false);
int t=1;
//cin>>t;
while(t--)solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3604kb
input:
5 3 6 5 2 4 7 6 4 2 8
output:
6
result:
ok 1 number(s): "6"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
1 2 1
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3784kb
input:
1 212055293 384338286
output:
384338286
result:
ok 1 number(s): "384338286"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3540kb
input:
99 749159996 323524232 125448341 365892333 481980673 143665393 394405973 44741918 687549448 513811513 287088118 385131171 11865696 666468353 449920567 373650719 671547289 116780561 41003675 671513243 351534153 507850962 374160874 985661954 222519431 600582098 987220654 704142246 856147059 37783620 1...
output:
507850962
result:
wrong answer 1st numbers differ - expected: '528957505', found: '507850962'