#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
#define fi first
#define se second
#define ld long double
#define vi vector<int>
#define vii vector<vector<int>>
#define all(v) (v).begin(), (v).end()
#define rep(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define per(i, b, a) for (int i = (b), _a = (a); i >= _a; --i)
using namespace std;
const int MOD = 1e9 + 7;
int add(int a, int b) {
a += b;
if (a >= MOD) a -= MOD;
return a;
}
int mul(int a, int b) {
(a *= b) %= MOD;
return a;
}
int bin_pow(int x, int y) {
int res=1;
while(y){if(y&1)res=res*x%MOD;x=x*x%MOD;y>>=1;}
return res;
}
const int INF = 1e17;
const int maxn = 2e6 + 5;
const int LG = 29;
int N, ans;
int a[maxn + 5], c[maxn + 5];
void solve(int tc) {
cin >> N;
rep(i, 1, N) cin >> a[i];
rep(j, 0, LG) {
vi b0, b1;
rep(i, 1, N) {
if (a[i] & (1ll << j)) b1.push_back(a[i]);
else b0.push_back(a[i]);
}
rep(i, 1, N) {
if (i <= (int)b0.size()) {
a[i] = b0[i - 1];
} else {
a[i] = b1[i - (int)b0.size() - 1];
}
c[i] = (a[i] & ((1ll << (j + 1)) - 1));
}
int pj = N, pk = N, pl = N;
rep(i, 1, N) {
pj = max(pj, i); pk = max(pk, i); pl = max(pl, i);
while (pj >= i && c[i] + c[pj] >= (1ll << j)) pj--;
while (pk >= i && c[i] + c[pk] >= (1ll << (j + 1))) pk--;
while (pl >= i && c[i] + c[pl] >= (1ll << j) + (1ll << (j + 1))) pl--;
if ((N - pl + pk - pj) & 1) ans ^= (1ll << j);
}
}
cout << ans;
}
/// 011
/// 1001
/// 110
/// 110
signed main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int tc = 1;
// cin >> tc;
for (int i = 1; i <= tc; ++i) {
solve(i);
}
}
Compilation message
xorsum.cpp: In function 'int main()':
xorsum.cpp:79:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
79 | freopen("input.txt", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |