QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#664987 | #7689. Flipping Cards | i0stream | WA | 0ms | 3880kb | C++14 | 942b | 2024-10-22 00:00:58 | 2024-10-22 00:00:59 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N=3*1e5+100;
int c[N],n,cnt1,cnt2;
struct node{
int a,b;
}p[N];
inline void tj(int x,int y){
if (x<y) cnt1++;
if (x>y) cnt2++;
}
bool check(int t){
int mx=0,l=1,ml=0,mr=0,cnt=0,d=0;
for (int i=1;i<=n;i++){
d=0;
if (p[i].a<t && p[i].b>=t) d=1;
if (p[i].a>=t && p[i].b<t) d=-1;
cnt+=d;
if (cnt>mx){
mx=cnt;
mr=i;ml=l;
}
if (cnt<0){
cnt=0;
l=i+1;
}
}
cnt1=0,cnt2=0;
for (int i=1;i<ml;i++) tj(p[i].a,t);
for (int i=ml;i<=mr;i++) tj(p[i].b,t);
for (int i=mr+1;i<=n;i++) tj(p[i].a,t);
return cnt1<=n/2 && cnt2<=n/2;
}
int main(){
scanf("%d",&n);
for (int i=1;i<=n;i++){
scanf("%d%d",&p[i].a,&p[i].b);
c[i]=p[i].a;
}
sort(c+1,c+n+1);
int l=c[n/2+1],r=1e9+1;
while (l<r){
if (l==r-1) break;
int mid=l+r>>1;
if (check(mid)) l=mid;
else r=mid;
}
printf("%d\n",l);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3872kb
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: 3840kb
input:
1 2 1
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3880kb
input:
1 212055293 384338286
output:
212055293
result:
wrong answer 1st numbers differ - expected: '384338286', found: '212055293'