#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 1e6+5;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n;
int v[MAXN];
pll b[MAXN], nw[MAXN];
int pw[50];
const int L = 31;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
cin>>n;
for(ll i = 0; i < n; i++){
cin>>v[i];
b[i] = {v[i] % 2, i};
}
sort(b, b + n);
pw[0] = 1;
for(int i = 1; i < L; i++){
pw[i] = pw[i - 1] * 2;
}
int ans = 0;
for(ll i = 0; i < L; i++){
ll cnt = 0;
int r3 = n, r2 = n, r1 = n;
for(int j = 0; j < n; j++){
while(r3 && b[j].ff + b[r3 - 1].ff >= pw[i] + pw[i + 1]) r3--;
while(r2 && b[j].ff + b[r2 - 1].ff >= pw[i + 1]) r2--;
while(r1 && b[j].ff + b[r1 - 1].ff >= pw[i]) r1--;
cnt += n - r1 - (r3 - r2);
}
for(int j = 0; j < n; j++){
if((2LL*b[j].ff) & pw[i]) cnt++;
}
//assert(cnt % 2 == 0);
cnt /= 2;
if(cnt % 2) ans += pw[i];
if(i + 1 == L) break;
int last = 0;
for(int j = 0; j < n; j++){
if((v[b[j].ss] & pw[i + 1]) == 0)
nw[last++] = b[j];
}
for(int j = 0; j < n; j++){
if((v[b[j].ss] & pw[i + 1]) != 0){
b[j].ff += pw[i + 1];
nw[last++] = b[j];
}
}
for(int j = 0; j < n; j++){
b[j] = nw[j];
nw[j] = {-1, -1};
}
//assert(last == n);
}
cout<<ans<<endl;
#ifdef Local
cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
#endif
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
512 KB |
Output is correct |
2 |
Correct |
7 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1112 ms |
35612 KB |
Output is correct |
2 |
Correct |
1097 ms |
33228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1112 ms |
35612 KB |
Output is correct |
2 |
Correct |
1097 ms |
33228 KB |
Output is correct |
3 |
Correct |
1376 ms |
35704 KB |
Output is correct |
4 |
Correct |
1194 ms |
34296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
512 KB |
Output is correct |
2 |
Correct |
7 ms |
512 KB |
Output is correct |
3 |
Correct |
133 ms |
3840 KB |
Output is correct |
4 |
Correct |
130 ms |
3932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
512 KB |
Output is correct |
2 |
Correct |
7 ms |
512 KB |
Output is correct |
3 |
Correct |
1112 ms |
35612 KB |
Output is correct |
4 |
Correct |
1097 ms |
33228 KB |
Output is correct |
5 |
Correct |
1376 ms |
35704 KB |
Output is correct |
6 |
Correct |
1194 ms |
34296 KB |
Output is correct |
7 |
Correct |
133 ms |
3840 KB |
Output is correct |
8 |
Correct |
130 ms |
3932 KB |
Output is correct |
9 |
Correct |
1567 ms |
35632 KB |
Output is correct |
10 |
Correct |
1444 ms |
35704 KB |
Output is correct |
11 |
Correct |
1479 ms |
35704 KB |
Output is correct |