QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#265695 | #7689. Flipping Cards | fishfishfriedfish# | WA | 1ms | 7704kb | C++14 | 1.2kb | 2023-11-25 20:26:46 | 2023-11-25 20:26:46 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define rep2(i,j,k) for(int i=j;i>=k;i--)
using namespace std;
template<typename T> void read(T &num){
char c=getchar();T f=1;num=0;
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){num=(num<<3)+(num<<1)+(c^48);c=getchar();}
num*=f;
}
template<typename T> void qwq(T x){
if(x>9)qwq(x/10);
putchar(x%10+'0');
}
template<typename T> void write(T x){
if(x<0){x=-x;putchar('-');}
qwq(x);putchar('\n');
}
int n;
int a[300010];int b[300010];
int c[600010];
int t[300010];
bool chk(int mid){
int cnt=0;
rep(i,1,n)cnt+=(a[i]>mid);
if(cnt>=(n-1)/2)return true;
rep(i,1,n){
t[i]=0;
if(a[i]>mid)t[i]--;
if(b[i]>mid)t[i]++;
t[i]+=t[i-1];
}
int mi=0;
rep(i,1,n){
if(cnt+t[i]-mi>=(n-1)/2)return true;
mi=min(mi,t[i]);
}
return false;
}
int main(){
read(n);
int len=0;
rep(i,1,n){
read(a[i]);
read(b[i]);
c[++len]=a[i];
c[++len]=b[i];
}
sort(c+1,c+len+1);
len=unique(c+1,c+len+1)-c-1;
int ll=1;int rr=len;int ans=0;
while(ll<=rr){
int mid=(ll+rr)>>1;
if(chk(c[mid])){ans=c[mid];ll=mid+1;}
else{rr=mid-1;}
}
write(ans);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7704kb
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: 1ms
memory: 7700kb
input:
1 2 1
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5664kb
input:
1 212055293 384338286
output:
384338286
result:
ok 1 number(s): "384338286"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 7696kb
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:
531535014
result:
wrong answer 1st numbers differ - expected: '528957505', found: '531535014'