#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 < 31; 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
for (int i = 0; i < ord.size(); i++) {
int zero = -1, one = -1, two = -1;
for (int step = i + 1; step >= 1; step /= 2) {
while (zero + step <= i && ((vec[zero + step] + vec[i]) >> bit) <= 0) zero += step;
while (one + step <= i && ((vec[one + step] + vec[i]) >> bit) <= 1) one += step;
while (two + step <= i && ((vec[two + step] + vec[i]) >> bit) <= 2) two += step;
}
int cntOne = one - zero + i - two;
if (cntOne & 1) ans ^= (1 << bit);
}
}
cout << ans << "\n";
return 0;
}
Compilation message
xorsum.cpp: In function 'int main()':
xorsum.cpp:41:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for (int i = 0; i < ord.size(); i++) {
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
592 KB |
Output is correct |
2 |
Correct |
9 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1639 ms |
26776 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1639 ms |
26776 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
592 KB |
Output is correct |
2 |
Correct |
9 ms |
592 KB |
Output is correct |
3 |
Correct |
240 ms |
3476 KB |
Output is correct |
4 |
Correct |
228 ms |
3292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
592 KB |
Output is correct |
2 |
Correct |
9 ms |
592 KB |
Output is correct |
3 |
Execution timed out |
1639 ms |
26776 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |