QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#241945 | #7689. Flipping Cards | muxiuyulin# | WA | 1ms | 5580kb | C++20 | 2.2kb | 2023-11-06 20:05:45 | 2023-11-06 20:05:45 |
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=200010;
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;
//cout<<t[i]<<" \n"[i==n];
t[i]+=t[i-1];
//cout<<t[i]<<" \n"[i==n];
}
int l=0,r=0,sum=0;
int mi=0,pos=0;
for(int i=1;i<=n;i++){
int x=t[i]-mi;
if(x>=sum){
sum=x;
l=pos+1;
r=i;
}
if(t[i]<=mi){
mi=t[i];
pos=i;
}
}
if(sum<=0) l=r=0;
vector<int> ans;
//cout<<l<<" "<<r<<" "<<sum<<endl;
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());
//for(auto t:ans) cout<<t<<" "; cout<<endl;
return ans[n/2]>=x;
}
int fun(){
int mx=0;
for(int l=1;l<=n;l++){
for(int r=l;r<=n;r++){
for(int k=l;k<=r;k++) swap(a[k],b[k]);
vector<int> ans;
for(int k=1;k<=n;k++) ans.push_back(a[k]);
sort(ans.begin(),ans.end());
mx=max(mx,ans[n/2]);
for(int k=l;k<=r;k++) swap(a[k],b[k]);
}
}
return mx;
}
void solve(){
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i]>>b[i];
check(45);
int l=1,r=1e9;
while(l<r){
int mid=(l+r+1)>>1;
//cout<<l<<" "<<r<<" "<<mid<<" "<<check(mid)<<endl;
if(check(mid)) l=mid;
else r=mid-1;
}
cout<<l<<endl;
// while(1){
// n=rnd()%10;
// if(n%2==0) n++;
// for(int i=1;i<=n;i++) a[i]=rnd()%100,b[i]=rnd()%100;
// int l=1,r=1e9;
// while(l<r){
// int mid=(l+r+1)>>1;
// if(check(mid)) l=mid;
// else r=mid-1;
// }
// int nl=fun();
// if(l!=nl){
// cout<<l<<" "<<nl<<endl;
// cout<<n<<endl;
// for(int i=1;i<=n;i++) cout<<a[i]<<" "<<b[i]<<endl;
// return ;
// }
// }
}
signed main(){
IOS;
int _=1;
//cin>>_;
while(_--){
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5460kb
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: 5516kb
input:
1 2 1
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5580kb
input:
1 212055293 384338286
output:
384338286
result:
ok 1 number(s): "384338286"
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 5572kb
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:
481980673
result:
wrong answer 1st numbers differ - expected: '528957505', found: '481980673'