1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| #include <cstdio> using namespace std; template <class Type> void read (Type &x) { char c; bool flag = false; while ((c = getchar()) < '0' || c > '9') c == '-' && (flag = true); x = c - '0'; while ((c = getchar()) >= '0' && c <= '9') x = (x << 1) + (x << 3) + c - '0'; flag && (x = ~x + 1); } template <class Type, class ...rest> void read (Type &x, rest &...y) { read(x), read(y...); } template <class Type> void write (Type x) { x < 0 && (putchar('-'), x = ~x + 1); x > 9 && (write(x / 10), 0); putchar('0' + x % 10); } const int N = 1e5 + 10, M = 1e6 + 10, K = 1e6; bool tr[2][M]; int n, w[N]; void add (bool *tr, int x) { for (++x; x <= K; x += x & -x) tr[x] ^= 1; } bool query (bool *tr, int x) { bool res = 0; for (++x; x; x -= x & -x) res ^= tr[x]; return res; } int main () { read(n); for (int i = 1; i <= n; ++i) read(w[i]), w[i] += w[i - 1]; int res = 0; add(tr[0], 0); for (int k = 0; k < 20; ++k) { bool s = 0; for (int i = 1; i <= n; ++i) { bool v = w[i] >> k & 1; int x = w[i] & (1 << k) - 1; s ^= query(tr[v ^ 1], x); s ^= query(tr[v], (1 << k) - 1) ^ query(tr[v], x); add(tr[v], x); } for (int i = 1; i <= n; ++i) { bool v = w[i] >> k & 1; int x = w[i] & (1 << k) - 1; add(tr[v], x); } res |= s << k; } write(res); return 0; }
|