ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#205188 | #3675. 反转卡牌 | drdilyor | 100 | 599ms | 12968kb | C++ | 867b | 2024-06-29 09:08:24 | 2024-06-29 12:00:41 |
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n;
int a[300005],b[300005];
int pa[300005],pb[300005],mx[300005];
bool check(int x){
int cc=0;
for(int i=1;i<=n;i++)cc+=(a[i]>=x);
if(cc>=(n+1)/2)return 1;
int cur=0;
for(int i=1;i<=n;i++)pa[i]=pa[i-1]+(a[i]>=x),pb[i]=pb[i-1]+(b[i]>=x);
mx[0]=0;
for(int i=1;i<=n;i++)mx[i]=max(mx[i-1],pa[i]-pb[i]);
for(int r=n;r>=1;r--){
//[l,r]
//0<=l<r
int to=(n+1)/2-cur;
//pb[r]-pb[l-1]+pa[l-1]>=to
if(mx[r-1]>=to-pb[r])return 1;
cur+=(a[r]>=x);
}
return 0;
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0);
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i]>>b[i];
int l=1,r=(int)1e9;
//有可能有 (n+1)/2 个数 >=x 吗?
int res=0;
while(l<=r){
int mid=(l+r)/2;
if(check(mid))res=mid,l=mid+1;
else r=mid-1;
}
cout<<res<<"\n";
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1268kb
input:
19 197442273 866376228 209699369 229863219 341205268 452287244 527782385 635863621 890709542 1618501...
output:
658806483
result:
ok single line: '658806483'
Test #2:
score: 10
Accepted
time: 0ms
memory: 1272kb
input:
19 80558401 589668176 508512627 960525401 175330329 291733316 402778560 979047609 816676402 14918706...
output:
604526894
result:
ok single line: '604526894'
Test #3:
score: 10
Accepted
time: 0ms
memory: 1268kb
input:
19 963674529 868249725 952550077 986154878 154679583 981436285 132550543 27264301 37610557 726458544...
output:
671306479
result:
ok single line: '671306479'
Test #4:
score: 10
Accepted
time: 76ms
memory: 12968kb
input:
299999 2 1 1 1 1 2 1 1 1 2 2 1 1 2 2 2 1 1 2 2 1 1 2 1 2 2 1 2 1 2 2 1 1 2 1 1 1 2 2 1 1 1 1 1 2 2 1...
output:
2
result:
ok single line: '2'
Test #5:
score: 10
Accepted
time: 78ms
memory: 12964kb
input:
299999 2 1 1 1 1 1 2 1 1 1 1 2 1 1 1 1 2 1 2 1 1 1 1 2 1 2 2 1 1 1 2 1 2 2 2 1 1 1 2 1 2 1 2 2 1 1 1...
output:
2
result:
ok single line: '2'
Test #6:
score: 10
Accepted
time: 74ms
memory: 12964kb
input:
299999 2 1 1 2 2 1 2 1 2 1 1 2 2 1 2 2 2 1 1 2 2 1 2 1 2 1 1 2 2 1 2 2 2 2 1 2 1 2 1 2 1 2 1 2 1 1 2...
output:
2
result:
ok single line: '2'
Test #7:
score: 10
Accepted
time: 85ms
memory: 12964kb
input:
299999 3668 7280 5593 2020 3377 1754 4223 1069 4132 6378 5659 151 3526 8630 4794 7594 3174 2362 4091...
output:
5001
result:
ok single line: '5001'
Test #8:
score: 10
Accepted
time: 81ms
memory: 12964kb
input:
299999 762144 548423 110669 792296 101795 531439 128695 201066 596823 499220 8966 764539 220356 2691...
output:
501013
result:
ok single line: '501013'
Test #9:
score: 10
Accepted
time: 97ms
memory: 12968kb
input:
299999 838703318 66046611 228148108 937693904 403316129 317948507 462357971 722210096 639416036 6600...
output:
501803202
result:
ok single line: '501803202'
Test #10:
score: 10
Accepted
time: 108ms
memory: 12968kb
input:
299999 253128201 108029132 848264776 291074930 394127700 623848386 575387893 445206981 126964628 390...
output:
500335844
result:
ok single line: '500335844'
Extra Test:
score: 0
Extra Test Passed