#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
if (!(cin >> n)) return 0;
vector<int> v(n);
for (int i = 0; i < n; ++i) cin >> v[i];
// Precalcul pentru diagonala: bitCount[b] = cate V_i au bitul b setat
const int MAXB = 31; // suficient pt sume pana la ~1e9
array<long long, MAXB> bitCount{}; // long long pentru n mare
for (int x : v) {
for (int b = 0; b < MAXB; ++b)
if (x & (1LL << b)) bitCount[b]++;
}
long long ans = 0;
vector<int> w(n);
for (int k = 0; k < 31; ++k) {
int mod = 1 << (k + 1); // 2^(k+1)
int half = 1 << k; // 2^k
int mask = mod - 1;
for (int i = 0; i < n; ++i) w[i] = v[i] & mask;
sort(w.begin(), w.end());
long long cntPairs = 0; // numar perechi i<j cu bitul k aprins
for (int i = 0; i < n; ++i) {
// Interval 1: [L1, R1] = [half - w[i], mod-1 - w[i]]
int L1 = half - w[i];
int R1 = (mod - 1) - w[i];
// Interval 2: [L2, R2] = [mod + half - w[i], 2*mod - 2 - w[i]]
int L2 = (mod + half) - w[i];
int R2 = (2 * mod - 2) - w[i];
// Taiere la [0, mod-1]
auto count_in = [&](int L, int R) -> long long {
if (L < 0) L = 0;
if (R > mask) R = mask;
if (L > R) return 0LL;
auto itL = lower_bound(w.begin() + i + 1, w.end(), L);
auto itR = upper_bound(w.begin() + i + 1, w.end(), R);
return max(0LL, (long long)(itR - itL));
};
cntPairs += count_in(L1, R1);
cntPairs += count_in(L2, R2);
}
// Paritatea perechilor i<j care aprind bitul k
int pairsParity = (int)(cntPairs & 1LL);
// Paritatea diagonelei (i=i): pentru k>=1 e paritatea bitCount[k-1]; pentru k=0 e 0
int diagParity = (k == 0) ? 0 : (int)(bitCount[k - 1] & 1LL);
if ((pairsParity ^ diagParity) == 1)
ans |= (1LL << k);
}
cout << ans << "\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... |