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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
#include <bits/stdc++.h>
struct InputOutputStream { enum { SIZE = 1 << 18 | 1 };
char ibuf[SIZE], *s, *t, obuf[SIZE], *oh;
~InputOutputStream() { fwrite(obuf, 1, oh - obuf, stdout); }
InputOutputStream() : s(), t(), oh(obuf) {}
inline char read() { return (s == t) && (t = (s = ibuf) + fread(ibuf, 1, SIZE, stdin)), s == t ? -1 : *s++; }
template <typename T> inline InputOutputStream &operator>>(T &x) { static char c; static bool iosig; for (c = read(), iosig = false; !isdigit(c); c = read()) { if (c == -1) return *this; iosig |= c == '-'; } for (x = 0; isdigit(c); c = read()) x = x * 10 + (c ^ '0'); iosig && (x = -x); return *this; }
inline void print(char c) { (oh == obuf + SIZE) && (fwrite(obuf, 1, SIZE, stdout), oh = obuf); *oh++ = c; }
template <typename T> inline void print(T x) { static int buf[21], cnt; if (x != 0) { (x < 0) && (print('-'), x = -x); for (cnt = 0; x; x /= 10) buf[++cnt] = x % 10 | 48; while (cnt) print((char)buf[cnt--]); } else { print('0'); } }
template <typename T> inline InputOutputStream &operator<<(const T &x) { print(x); return *this; } } io;
const int MAX_LOG = 31; const int MAXN = 500000; const int MAXM = 1048576 + 1;
struct LinearBasis { unsigned int a[MAX_LOG];
inline void insert(unsigned int x) { for (int i; x;) { if (a[i = MAX_LOG - __builtin_clz(x)]) { x ^= a[i]; } else { a[i] = x; break; } } }
inline unsigned int query() { unsigned int ret = 0; for (int i = MAX_LOG - 1; i >= 0; i--) if ((ret ^ a[i]) > ret) ret ^= a[i]; return ret; }
inline unsigned int &operator[](int i) { return a[i]; }
inline const unsigned int &operator[](int i) const { return a[i]; } } d[MAXM];
int M, n;
std::map<int, int> map;
inline void modify(int s, int t, int x) { for (s = s + M - 1, t = t + M + 1; s ^ t ^ 1; s >>= 1, t >>= 1) { if (~s & 1) d[s ^ 1].insert(x); if (t & 1) d[t ^ 1].insert(x); } }
int main() { io >> n; for (M = 1; M < n + 2;) M <<= 1; for (int i = 1, x; i <= n; i++) { io >> x; if (x > 0) { map[x] = i; } else { std::map<int, int>::iterator it = map.find(-x); modify(it->second, i - 1, -x); map.erase(it); } } for (std::map<int, int>::iterator it = map.begin(); it != map.end(); ++it) modify(it->second, n, it->first); for (int i = 1; i < M; i++) { for (int j = 0; j < MAX_LOG; j++) { d[i << 1].insert(d[i][j]); d[i << 1 | 1].insert(d[i][j]); } } for (int i = 1; i <= n; i++) io << d[i + M].query() << '\n'; return 0; }
|