Submission #1312795

#TimeUsernameProblemLanguageResultExecution timeMemory
1312795neonglitchXOR Sum (info1cup17_xorsum)C++20
45 / 100
1695 ms29656 KiB
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define int ll
const int N=1e6+2;
int a[N],c[N],ord[N],n,pw=1;
int get(int R)
{
	int i=0,ans=0;
	// cout<<"We want "<<R<<endl;
	// cout<<"Array ";
	// for(int i=0;i<n;i++)cout<<a[ord[i]]%pw<<' ';
	// cout<<endl;
	while(i+1<n and (a[ord[i]]%pw)+(a[ord[0]]%pw)<R)
	{
		i++;
	}
	for(int j=0;j<n;j++)
	{
		while(i>=0 and (a[ord[i]]%pw)+(a[ord[j]]%pw)>=R)
		{
			i--;
		}
		// cout<<"two po "<<j<<' '<<i<<endl;
		ans+=(i+1);
	}
	// cout<<"answer "<<ans<<endl;
	// int cntp=0;
	// for(int i=0;i<n;i++)
	// {
		// cout<<"For "<<i<<' ';
		// for(int j=0;j<n;j++)
		// {
			// if((a[ord[i]]%pw)+(a[ord[j]]%pw) < R)
			// {
				// cout<<j<<' ';
				// cntp++;
			// }
		// }
		// cout<<endl;
	// }
	// cout<<"REAL "<<cntp<<endl;
	return ans;
}
int nxt[2][N],pto[3];
main()
{
	// int t=1;
	// cin>>t;
	// while(t--)
	{
		cin>>n;
		for(int i=0;i<n;i++)
		{
			cin>>a[i];
			ord[i]=i;
		}
		int fnl=0;
		for(int j=0;j<31;j++)
		{
			pw*=2;
			pto[0]=0;
			pto[1]=0;
			for(int i=0;i<n;i++)
			{
				bool pq=((a[ord[i]]>>j)&1);
				if(pq)
				{
					nxt[1][pto[1]++]=ord[i];
				}
				else{
					nxt[0][pto[0]++]=ord[i];
				}
			}
			int lpt=0;
			for(int i=0;i<pto[0];i++)ord[lpt++]=nxt[0][i];
			for(int i=0;i<pto[1];i++)ord[lpt++]=nxt[1][i];
			int on=get(pw)-get(pw/2);
			on += get(2*pw)-get(pw+(pw/2));
			for(int i=0;i<n;i++) 
			{
				int x=(a[(ord[i])]%pw)*2;
				if(x<pw and x>=(pw/2))
				{
					on++;
				}
				if(x<2*pw and x>=(pw+(pw/2)))
				{
					on++;
				}
			}
			on/=2;
			if(on&1)fnl+=pw/2;
		}
		cout<<fnl<<endl;
	}
}

Compilation message (stderr)

xorsum.cpp:50:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   50 | main()
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...