#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tpl;
#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n; cin >> n;
vector<int> a(n), ord(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
ord[i] = i;
}
int ans = 0;
for (int bit = 0; bit < 30; bit++) {
// sort
vector<int> zeroBit, oneBit, vec(n);
for (int u : ord) {
if ((a[u] >> bit) & 1) oneBit.push_back(u);
else zeroBit.push_back(u);
}
ord = zeroBit, ord.insert(ord.end(), all(oneBit));
// last (`bit` + 1) bits
for (int i = 0; i < n; i++)
vec[i] = a[ord[i]] & ((1 << (bit + 1)) - 1);
// calculate
int zero = -1, one = -1, two = -1;
for (int i = (int)ord.size() - 1; i >= 0; i--) {
zero = min(zero, i), one = min(one, i), two = min(two, i);
while (zero + 1 <= i && ((vec[zero + 1] + vec[i]) >> bit) <= 0) zero++;
while (one + 1 <= i && ((vec[one + 1] + vec[i]) >> bit) <= 1) one++;
while (two + 1 <= i && ((vec[two + 1] + vec[i]) >> bit) <= 2) two++;
int cntOne = one - zero + i - two;
if (cntOne & 1) ans ^= (1 << bit);
}
}
cout << ans << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
336 KB |
Output is correct |
2 |
Correct |
3 ms |
552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
487 ms |
22628 KB |
Output is correct |
2 |
Correct |
424 ms |
20224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
487 ms |
22628 KB |
Output is correct |
2 |
Correct |
424 ms |
20224 KB |
Output is correct |
3 |
Correct |
516 ms |
23152 KB |
Output is correct |
4 |
Correct |
464 ms |
21112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
336 KB |
Output is correct |
2 |
Correct |
3 ms |
552 KB |
Output is correct |
3 |
Correct |
62 ms |
2460 KB |
Output is correct |
4 |
Correct |
58 ms |
2460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
336 KB |
Output is correct |
2 |
Correct |
3 ms |
552 KB |
Output is correct |
3 |
Correct |
487 ms |
22628 KB |
Output is correct |
4 |
Correct |
424 ms |
20224 KB |
Output is correct |
5 |
Correct |
516 ms |
23152 KB |
Output is correct |
6 |
Correct |
464 ms |
21112 KB |
Output is correct |
7 |
Correct |
62 ms |
2460 KB |
Output is correct |
8 |
Correct |
58 ms |
2460 KB |
Output is correct |
9 |
Correct |
564 ms |
23592 KB |
Output is correct |
10 |
Correct |
630 ms |
21640 KB |
Output is correct |
11 |
Correct |
613 ms |
22824 KB |
Output is correct |