QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#594108#7932. AND-OR closureATM12345#WA 0ms3716kbC++171.1kb2024-09-27 19:14:592024-09-27 19:15:00

Judging History

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

  • [2024-09-27 19:15:00]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3716kb
  • [2024-09-27 19:14:59]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define Ma 1000005 
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(x) x.begin(),x.end()
#define N 40

using namespace std;


ll n;
ll a[Ma];

ll ans=0;


void sol()
{
	ll n;
	cin>>n;
	vector <ll> v;
	for (ll i=1;i<=n;i++){
		ll x;
		cin>>x;
		v.pb(x);
	}
	sort(all(v));
	ll ans=n;
	for (ll k=N-1;k>=0;k--){
		vector <ll> l,r;
		for (auto z:v)
		{
			if (z>>k&1)
				l.pb(z-(1ll<<k));
			else
				r.pb(z);
		}
		vector <ll> ne;
		ll le=0,re=0;
		if (l.size()&&r.size())
			ans+=v.size();
		while (le<l.size()||re<r.size())
		{
			if (le<l.size()&&(re==r.size()||l[le]<r[re]))
			{
				if (ne.size()&&l[le]==ne.back())
					ans-=2,le++;
				else
					ne.pb(l[le++]);
			}
			else
			{
				if (ne.size()&&r[re]==ne.back())
					ans-=2,re++;
				else
					ne.pb(r[re++]);
			}
		}
		swap(v,ne);
		//printf("k=%lld ans=%lld\n",k,ans);
		
	}
	printf("%lld\n",ans);
}



int main()
{
	IOS
	ll tt=1;
	//cin>>tt;
	while (tt--)
		sol();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3716kb

input:

4
0 1 3 5

output:

7

result:

wrong answer 1st numbers differ - expected: '5', found: '7'