#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define fi first
#define se second
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int rand(int l,int r){return uniform_int_distribution<int>(l, r)(rng);}
inline ll rand(ll l,ll r){return uniform_int_distribution<ll>(l, r)(rng64);}
#ifdef DEBUG
auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X)
#else
#define debug(...){}
#endif
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
const int MAXN = 1e6 + 7;
const int MAXK = 30;
int A[MAXN];
ll res[MAXK];
int n;
void solve(vi vec, int k){
if(k == MAXK){
return;
}
//debug(vec);
//debug(k);
//jest posortowany
ll mod = (1LL << (k + 1));
ll p2 = (1LL << k);
vector<pll> range = {mp(p2, 2 * p2 - 1), mp(3 * p2, 4 * p2 - 1)};
for(int i = 0; i < 2; i++){
int wsk1 = 0;
int wsk2 = 0;
//debug(range[i]);
//for(auto ele : vec){
// cerr << (A[ele] % mod) << ' ';
// }
//cerr << '\n';
for(int j = 0; j < n; j++){
ll curr = A[vec[j]] % mod;
while(wsk2 + 1 <= j && curr + (A[vec[wsk2 + 1]] % mod) <= range[i].se){
wsk2++;
}
while(wsk1 < wsk2 && curr + (A[vec[wsk1]] % mod) < range[i].fi){
wsk1++;
}
// cerr << j << ' ' << curr << ' ' << wsk1 << ' ' << wsk2 << '\n';
if(curr + (A[vec[wsk1]] % mod) >= range[i].fi && curr + (A[vec[wsk1]] % mod) <= range[i].se){
// cerr << "ADD: " << k << ' ' << wsk2 - wsk1 + 1 << '\n';
res[k] = (ll)res[k] + wsk2 - wsk1 + 1;
}
}
}
//posortuj
vi vec0, vec1;
for(auto ele : vec){
if(A[ele] & mod){
vec1.pb(ele);
}else{
vec0.pb(ele);
}
}
vec0.insert(vec0.end(), all(vec1));
solve(vec0, k + 1);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
vi pos0, pos1;
for(int i = 1; i <= n; i++){
cin >> A[i];
if(A[i] & 1){
pos1.pb(i);
}else{
pos0.pb(i);
}
}
pos0.insert(pos0.end(), all(pos1));
solve(pos0, 0);
ll ksor = 0LL;
for(int i = 0; i < MAXK; i++){
if(res[i] & 1){
ksor = (ll)ksor + (1LL << i);
}
}
cout << ksor << '\n';
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |