Submission #337836

# Submission time Handle Problem Language Result Execution time Memory
337836 2020-12-22T01:11:07 Z nandonathaniel XOR Sum (info1cup17_xorsum) C++14
45 / 100
1600 ms 9580 KB
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
using namespace std;
const int MAXN=1e6+5;
int a[MAXN],b[MAXN];

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n,ans=0;
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> a[i];
	}
	for(int i=0;i<29;i++){
		for(int j=1;j<=n;j++)b[j]=a[j]&((1<<(i+1))-1);
		sort(b+1,b+n+1);
//		for(int j=1;j<=n;j++)cout << b[j] << " ";
//		cout << '\n';
		int ret=0;
		for(int j=1;j<=n;j++){
			int ki=j,ka=n,res=-1;
			while(ki<=ka){
				int mid=(ki+ka)/2;
				if(b[j]+b[mid]>=(1<<i)){
					res=mid;
					ka=mid-1;
				}
				else ki=mid+1;
			}
			int awalkel2,awalkel3,awalkel4;
			if(res!=-1){
				if(b[j]+b[res]<(1<<(i+1))){
					awalkel2=res;
					ki=res+1;ka=n;res=-1;
					while(ki<=ka){
						int mid=(ki+ka)/2;
						if(b[j]+b[mid]>=(1<<(i+1))){
							res=mid;
							ka=mid-1;
						}
						else ki=mid+1;
					}
					if(res!=-1){
						if(b[j]+b[res]<=(3*(1<<i))-1){
							awalkel3=res;
							ki=res+1;ka=n;res=-1;
							while(ki<=ka){
								int mid=(ki+ka)/2;
								if(b[j]+b[mid]>=3*(1<<i)){
									res=mid;
									ka=mid-1;
								}
								else ki=mid+1;
							}
							if(res!=-1){
								awalkel4=res;
								if((awalkel3-awalkel2+n-awalkel4+1)&1)ret^=(1<<i);
							}
							else{
								if((awalkel3-awalkel2)&1)ret^=(1<<i);
							}
						}
						else{
							awalkel4=res;
							if((n+1-awalkel2)&1)ret^=(1<<i);
						}
					}
					else{
						if((n+1-awalkel2)&1)ret^=(1<<i);
					}
				}
				else if(b[j]+b[res]<=(3*(1<<i))-1){
					awalkel3=res;
					ki=res+1;ka=n;res=-1;
					while(ki<=ka){
						int mid=(ki+ka)/2;
						if(b[j]+b[mid]>=3*(1<<i)){
							res=mid;
							ka=mid-1;
						}
						else ki=mid+1;
					}
					if(res!=-1){
						awalkel4=res;
						if((n-awalkel4+1)&1)ret^=(1<<i);
					}
				}
				else{
					awalkel4=res;
					if((n-awalkel4+1)&1)ret^=(1<<i);
				}
			}
		}
		ans+=ret;
	}
	cout << ans << '\n';
	return 0;
}

Compilation message

xorsum.cpp:3: warning: ignoring #pragma GCC option [-Wunknown-pragmas]
    3 | #pragma GCC option("arch=native","tune=native","no-zero-upper")
      |
# Verdict Execution time Memory Grader output
1 Correct 15 ms 364 KB Output is correct
2 Correct 15 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1648 ms 9580 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1648 ms 9580 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 364 KB Output is correct
2 Correct 15 ms 384 KB Output is correct
3 Correct 420 ms 2028 KB Output is correct
4 Correct 423 ms 2156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 364 KB Output is correct
2 Correct 15 ms 384 KB Output is correct
3 Execution timed out 1648 ms 9580 KB Time limit exceeded
4 Halted 0 ms 0 KB -