QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#241914#7689. Flipping Cardsmuxiuyulin#WA 1ms5672kbC++201.3kb2023-11-06 19:31:482023-11-06 19:31:48

Judging History

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

  • [2023-11-06 19:31:48]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5672kb
  • [2023-11-06 19:31:48]
  • 提交

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=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;
	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();
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 5672kb

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

input:

1
2 1

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 0
Accepted
time: 1ms
memory: 5572kb

input:

1
212055293 384338286

output:

384338286

result:

ok 1 number(s): "384338286"

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 5608kb

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'