QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#241911#7689. Flipping Cardsmuxiuyulin#WA 1ms5508kbC++201.3kb2023-11-06 19:29:452023-11-06 19:29:46

Judging History

你现在查看的是最新测评结果

  • [2023-11-06 19:29:46]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5508kb
  • [2023-11-06 19:29:45]
  • 提交

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;
		t[i]+=t[i-1];
		//cout<<t[i]<<" \n"[i==n];
	}
	int l=0,r=0,sum=t[1];
	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;
	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];
	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: 5448kb

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: 5508kb

input:

1
2 1

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 5448kb

input:

1
212055293 384338286

output:

212055293

result:

wrong answer 1st numbers differ - expected: '384338286', found: '212055293'