QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#245732#7689. Flipping CardsnoneWA 0ms3784kbC++142.0kb2023-11-10 10:46:552023-11-10 10:46:56

Judging History

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

  • [2023-11-10 10:46:56]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3784kb
  • [2023-11-10 10:46:55]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+6;
#define ll long long
#define int long long

void solve()
{
	int n;
	cin>>n;
	vector<ll>a(n+1),b(n+1),c(n+1),d(n+1);
	for(int i=1;i<=n;i++)cin>>a[i],c[i]=i;
	for(int i=1;i<=n;i++)cin>>b[i],d[i]=i;
	int l=1,r=n,ans=0;
	sort(c.begin()+1,c.end(),[=](auto x,auto y){
		return a[x]<a[y];
	});
	while(l<=r){
		int mid=(l+r)>>1;
		auto check1=[=](int k)->bool{
			int bl=0,br=0;
			for(int i=1;i<k;i++){
				if(a[i]>=a[k])bl++;
			}
			for(int i=k+1;i<=n;i++){
				if(a[i]>=a[k])br++;
			}
			int sum=0,ans=0;
			for(int i=1;i<k;i++){
				int yl=(a[i]>=a[k]),now=(b[i]>=a[k]);
				int num=now-yl;
				if(sum<0)sum=0;
				sum=sum+num;
				ans=max(ans,sum);
			}
			int res=bl+br;
			res=max(res,ans+bl+br);
			sum=0,ans=0;
			for(int i=k+1;i<=n;i++){
				int yl=(a[i]>=a[k]),now=(b[i]>=a[k]);
				int num=now-yl;
				if(sum<0)sum=0;
				sum=sum+num;
				ans=max(ans,sum);
			}
			res=max(res,ans+bl+br);
			//cout<<ans<<" "<<bl<<" "<<br<<" "<<k<<endl;
			if(res>=n/2)return true;
			return false;
		};
		if(check1(c[mid]))ans=mid,l=mid+1;
		else r=mid-1;
	}
	ll res=0;
	//cout<<c[ans]<<endl;
	res=a[c[ans]];
	sort(c.begin()+1,c.end(),[=](auto x,auto y){
		return b[x]<b[y];
	});
	l=1,r=n,ans=0;
		while(l<=r){
		int mid=(l+r)>>1;
		auto check2=[=](int k)->bool{
			int ans=0;
			for(int i=1;i<=n;i++){
				if(a[i]>=b[k]&&i!=k)ans++;
			}
			int ansl=0,ansr=0,sum=0;
			for(int i=k+1;i<=n;i++){
				int yl=(a[i]>=b[k]),now=(b[i]>=b[k]);
				int num=now-yl;
				sum+=num;
				ansr=max(ansr,sum);
			}
			sum=0;
			for(int i=k-1;i>=1;i--){
				int yl=(a[i]>=b[k]),now=(b[i]>=b[k]);
				int num=now-yl;
				sum+=num;
				ansl=max(ansl,sum);
			}
			if(ans+ansl+ansr>=n/2)return true;
			return false;
		};
		if(check2(c[mid]))ans=mid,l=mid+1;
		else r=mid-1;
	}
	res=max(res,b[c[ans]]);
	cout<<res<<endl;
}
signed  main(){
	ios::sync_with_stdio(false);	
	int t=1;
	//cin>>t;
	while(t--)solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

input:

1
2 1

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3784kb

input:

1
212055293 384338286

output:

384338286

result:

ok 1 number(s): "384338286"

Test #4:

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

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:

507850962

result:

wrong answer 1st numbers differ - expected: '528957505', found: '507850962'