# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
681382 | 2023-01-12T21:50:49 Z | iosif_andrei_ | XOR Sum (info1cup17_xorsum) | C++14 | 1051 ms | 37636 KB |
#include <bits/stdc++.h> using namespace std; int v[1000001], X[1000001], n, POW[32], szX, szY, low[1000001], high[1000001]; int* vp, * xp; bool bit; struct poz { int val, i; }a[1000002], x[1000001], y[1000001]; bitset <1000001> b; int main() { cin >> n; int maxi = 0; for (int i = 0; i <= 30; i++) POW[i] = (1 << i); for (int i = 1; i <= n; i++) { cin >> v[i]; maxi = max(maxi, v[i]); } int l, r, m, poz1, poz2, poz; int res = 0, downLim, upLim, aux, sz, i; for (int i = 1; i <= n; i++) a[i].i = i, a[i].val = 0; for (int k = 0; k <= 29; k++) { bit = false; vp = v; vp++; xp = X; xp++; szX = szY = 0; for (i = 1; i <= n; i++) { if (*vp & 1) *xp += POW[k], b[i] = true; else b[i] = false; *vp >>= 1; vp++; xp++; } for (i = 1; i <= n; i++) if (b[a[i].i]) a[i].val += POW[k], y[++szY] = a[i]; else x[++szX] = a[i]; for (i = 1; i <= szX; i++) a[i] = x[i]; for (int i = 1; i <= szY; i++) a[szX + i] = y[i]; aux = (1 << k) + (1 << (k + 1)); downLim = POW[k]; upLim = POW[k + 1] - 1; l = 1, r = 1; while (r <= n && a[l].val + a[r].val < aux) r++; if (r == n + 1) { while (l <= n && a[l].val + a[n].val < aux) l++; r = n; } if (l != n + 1 && r != n + 1) { while (l < r) { while (l < r && a[l].val + a[r - 1].val >= aux) r--; bit ^= (n - r + 1) & 1; l++; } while (l <= n) bit ^= (n - (l++) + 1) & 1; } int last = n; for (int i = 1; i <= n; i++) { if (a[i].val + a[n].val < downLim) { low[i] = 0; continue; } while (last > 1 && a[i].val + a[last - 1].val >= downLim) last--; if (last < i) low[i] = i; else low[i] = last; } l = 1, r = n; while (l <= r && a[l].val + a[r].val > upLim) r--; while (l <= r) { high[l] = r; l++; while (l <= r && a[l].val + a[r].val > upLim) r--; } while (l <= n) high[l++] = 0; for (i = 1; i <= n; i++) if (low[i] && high[i] && low[i] <= high[i]) bit ^= (high[i] - low[i] + 1) & 1; if (bit) res += POW[k]; } cout << res; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 468 KB | Output is correct |
2 | Correct | 5 ms | 468 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 596 ms | 37636 KB | Output is correct |
2 | Correct | 580 ms | 35068 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 596 ms | 37636 KB | Output is correct |
2 | Correct | 580 ms | 35068 KB | Output is correct |
3 | Correct | 824 ms | 37500 KB | Output is correct |
4 | Correct | 741 ms | 36268 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 468 KB | Output is correct |
2 | Correct | 5 ms | 468 KB | Output is correct |
3 | Correct | 105 ms | 4044 KB | Output is correct |
4 | Correct | 125 ms | 3952 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 468 KB | Output is correct |
2 | Correct | 5 ms | 468 KB | Output is correct |
3 | Correct | 596 ms | 37636 KB | Output is correct |
4 | Correct | 580 ms | 35068 KB | Output is correct |
5 | Correct | 824 ms | 37500 KB | Output is correct |
6 | Correct | 741 ms | 36268 KB | Output is correct |
7 | Correct | 105 ms | 4044 KB | Output is correct |
8 | Correct | 125 ms | 3952 KB | Output is correct |
9 | Correct | 1051 ms | 37476 KB | Output is correct |
10 | Correct | 1030 ms | 37476 KB | Output is correct |
11 | Correct | 1034 ms | 37476 KB | Output is correct |