Submission #1149781

#TimeUsernameProblemLanguageResultExecution timeMemory
1149781adlinXOR Sum (info1cup17_xorsum)C++20
45 / 100
1693 ms8008 KiB
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define F first
#define S second
#define all(v) (v).begin(),(v).end()
#define ull unsigned long long
#define ahahahant ios_base::sync_with_stdio(0);cin.tie(0); 
//#define int long long

using namespace std;

//mt19937 rng( chrono::steady_clock::now().time_since_epoch().count());
// 
//ll rand( ll l, ll r )
//{
//    uniform_int_distribution <ll> uid( l, r );
//    return uid( rng );
//}

ll lcm(ll x, ll y){
	return x / __gcd(x,y) * y;
}

ll binpow(ll a, ll b, ll m){
	if(!b) return 1ll;
	if(b & 1) return binpow(a,b-1,m) * a % m;
	ll res = binpow(a,b/2,m) % m;
	return res * res % m;
}

const int maxn = 1e6 + 6;

const int mod = 1e9 + 7;

const int mod2 = 998244353;

const ll inf = 1e18;

const int inf2 = 1e9;

const int K = 300;

int n,a[maxn],b[maxn];

ll cnt[30];

int pw[30];

void who(){
		
	cin >> n;
	
	pw[0] = 1;
	
	for(int i = 1; i < 30; i++){
		pw[i] = pw[i - 1] + pw[i - 1];
	}
	
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
		
	for(int k = 0; k < 30; k++){
		for(int i = 1; i <= n; i++) b[i] = a[i];
		for(int i = 1; i <= n; i++){
			for(int k2 = k + 1; k2 < 30; k2++){
				if(b[i] & pw[k2]){
					b[i] -= pw[k2];
				}
			}
		}
		sort(b + 1, b + n + 1);
		for(int i = 1; i <= n; i++){
			int l = i, r = n;
			
			int tl = -1, tr = -1;
			
			while(l <= r){
				int md = (l + r) >> 1;
				
				if(b[i] + b[md] >= pw[k]){
					tl = md;
					r = md - 1;
				}
				else {
					l = md + 1;
				}
			}
			
			l = i, r = n;
			
			while(l <= r){
				int md = (l + r) >> 1;
				
				if(b[i] + b[md] < pw[k + 1]){
					tr = md;	
					l = md + 1;
				}
				else {
					r = md - 1;
				}
				
			}
			
			if(tl != -1 && tr != -1) cnt[k] += (tr - tl + 1);
			
			l = i, r = n;
			
			tl = -1;
			
			while(l <= r){
				int md = (l + r) >> 1;
				
				if(b[i] + b[md] >= pw[k + 1] + pw[k]){
					tl = md;
					r = md - 1;
				}
				else {
					l = md + 1;
				}
				
			}
			
			if(tl != -1) cnt[k] += (n - tl + 1);
			
		}
	}
		
	ll ans = 0;
	
	for(int i = 0; i < 30; i++){
		if(cnt[i] & 1) ans += pw[i];
	}
		
	cout << ans;
		
}

signed main(){
	
//	freopen("yinyang.in", "r", stdin);
//	freopen("yinyang.out", "w", stdout);
	
	ahahahant
		
	int tt = 1;
	
//	cin >> tt;
	
	while(tt--){
		who();
	}
	
	
	return 0;
}

/*
__builtin_popcount
__builtin_clz
__builtin_ctz
__builtin_parity

int get(int r){
	int res = 0;
	for(; r >= 0; r = (r & (r + 1)) - 1) res += f[r];
	return res;
}
 
void upd(int i, int val){
	for(; i <= n; i = (i | (i + 1))) f[i] += val;
}
*/ 	
#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...