QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#241899 | #7689. Flipping Cards | muxiuyulin# | WA | 1ms | 7916kb | C++20 | 1.4kb | 2023-11-06 19:11:10 | 2023-11-06 19:11:10 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define endl "\n"
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(int i=(int)a,i##i=(int)b;i<=i##i;i++)
#define per(i,a,b) for(int i=(int)a,i##i=(int)b;i>=i##i;i--)
mt19937_64 rnd(random_device{}());
#define int ll
typedef pair<int,int> pii;
const int N=400010;
const int mod=998244353;
int n,a[N],b[N],t[N];
int check(int x){
for(int i=1;i<=n;i++){
if(a[i]>=x&&b[i]>=x) t[i]=1;
if(a[i]>=x&&b[i]<x) t[i]=-1;
if(a[i]<x&&b[i]>=x) t[i]=1;
if(a[i]<x&&b[i]<x) t[i]=0;
t[i]+=t[i-1];
//cout<<t[i]<<" \n"[i==n];
}
int l=1,r=1,sum=t[1];set<pii> s;
s.insert({0,1});
for(int i=1;i<=n;i++){
pii c=*(s.begin());
int x=t[i]-c.first;
if(x>sum){
sum=x;
l=c.second;
r=i;
}
s.insert({t[i],i});
}
if(sum<=0) l=r=0;
//cout<<l<<" "<<r<<" "<<sum<<endl;
vector<int> ans;
for(int i=1;i<=n;i++){
if(i>=l&&i<=r) ans.push_back(b[i]);
else ans.push_back(a[i]);
}
sort(ans.begin(),ans.end());
return ans[n/2]>=x;
}
void solve(){
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i]>>b[i];
check(6);
int l=1,r=1e9;
while(l<r){
int mid=(l+r+1)>>1;
if(check(mid)) l=mid;
else r=mid-1;
}
cout<<l<<endl;
}
signed main(){
IOS;
int _=1;
//cin>>_;
while(_--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7916kb
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: 7908kb
input:
1 2 1
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 0ms
memory: 7696kb
input:
1 212055293 384338286
output:
384338286
result:
ok 1 number(s): "384338286"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 7664kb
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:
475996557
result:
wrong answer 1st numbers differ - expected: '528957505', found: '475996557'