QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#237799 | #7689. Flipping Cards | ucup-team958# | WA | 0ms | 7728kb | C++14 | 1.2kb | 2023-11-04 15:02:27 | 2023-11-04 15:02:27 |
Judging History
answer
//Man always remember love because of romance only!
#include<bits/stdc++.h>
using namespace std;
inline int read(){
int X=0,w=0; char ch=0;
while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
return w?-X:X;
}
inline void write(int x){
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10+'0');
}
int a[300001],b[300001];
int n;
int c[300001];
int tp;
int check(int x){
for(int i=1;i<=n;i++){
c[i]=(b[i]>=x)-(a[i]>=x);
}
int ans=0,now=0,l=1,r=0;
int ansl=1,ansr=0;
for(int i=1;i<=n;i++){
if(now+c[i]<c[i]) now=c[i],l=i,r=i;
else now+=c[i],r++;
if(now>ans) ansl=l,ansr=r;
ans=max(ans,now);
}
int res=0;
for(int i=1;i<=n;i++) res+=(a[i]>=x);
if(res<=(n+1)/2&&res+ans>=(n+1)/2){
tp=x;
return 1;
}
if(res>(n+1)/2) return 1;
return 0;
}
int d[600001];
int main(){
n=read();
int cnt=0;
for(int i=1;i<=n;i++){
a[i]=read(),b[i]=read();
d[++cnt]=a[i],d[++cnt]=b[i];
}
sort(d+1,d+cnt+1);
int l=1,r=cnt,res;
while(l<=r){
int mid=(l+r)/2;
if(check(d[mid])) res=mid,l=mid+1;
else r=mid-1;
}
write(tp);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 7636kb
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: 5648kb
input:
1 2 1
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 0ms
memory: 5548kb
input:
1 212055293 384338286
output:
384338286
result:
ok 1 number(s): "384338286"
Test #4:
score: 0
Accepted
time: 0ms
memory: 7628kb
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:
528957505
result:
ok 1 number(s): "528957505"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 7728kb
input:
101 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000...
output:
0
result:
wrong answer 1st numbers differ - expected: '1000000000', found: '0'