# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
45673 | aome | XOR Sum (info1cup17_xorsum) | C++17 | 1317 ms | 56396 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
int n;
int res;
int a[N];
int b[N];
bool p[35][N];
int arr[N];
int f[2][N];
int buf[2][N];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
for (int j = 0; j < 30; ++j) {
p[j][i] = a[i] >> j & 1;
}
}
for (int i = 0; i < n; ++i) arr[i] = i;
for (int i = 0; i <= 30; ++i) {
// cout << "#\n";
// for (int j = 0; j < n; ++j) cout << arr[j] << ' ' << b[arr[j]] << '\n';
for (int j = n - 1; j >= 0; --j) {
f[0][j] = f[0][j + 1], f[1][j] = f[1][j + 1];
f[p[i][arr[j]]][j]++;
}
int cur = 0, ptr = n;
int cnt[2];
cnt[0] = cnt[1] = 0;
for (int j = 0; j < n; ++j) {
if (ptr < j) {
cnt[p[i][arr[ptr]]]--, ptr++;
}
while (ptr > j && b[arr[ptr - 1]] + b[arr[j]] >= (1 << i)) {
ptr--, cnt[p[i][arr[ptr]]]++;
}
int cnt2[2];
cnt2[0] = f[0][j] - cnt[0];
cnt2[1] = f[1][j] - cnt[1];
cur ^= cnt[p[i][arr[j]]] & 1;
cur ^= cnt2[p[i][arr[j]] ^ 1] & 1;
}
res += cur << i;
if (i == 30) break;
int sz[2];
sz[0] = sz[1] = 0;
for (int j = 0; j < n; ++j) {
b[j] += p[i][j] << i;
}
for (int j = 0; j < n; ++j) {
bool x = p[i][arr[j]]; buf[x][sz[x]++] = arr[j];
}
for (int j = 0; j < sz[0]; ++j) {
arr[j] = buf[0][j];
}
for (int j = 0; j < sz[1]; ++j) {
arr[j + sz[0]] = buf[1][j];
}
}
cout << res;
}
Compilation message (stderr)
# | 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... |