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
| #include <cstdio> #include <algorithm> #include <cstring> #include <iostream> #define ll long long #define INF 0x3f3f3f3f using namespace std;
int rd() { int x = 0, w = 1; char c = getchar();
while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
while(c >= '0' && c <= '9') { x = x * 10 + (c - '0'); c = getchar(); }
return x * w; }
const int N = 600005;
int trie[N * 24][2], lat[N * 24]; int s[N], rt[N], n, m, tot;
void add(int i, int k, int p, int q) { if(k < 0) { lat[q] = i; return ; }
int c = (s[i] >> k) & 1; if(p) trie[q][c ^ 1] = trie[p][c ^ 1]; trie[q][c] = ++tot; add(i, k - 1, trie[p][c], trie[q][c]); lat[q] = max(lat[trie[q][0]], lat[trie[q][1]]); }
int ask(int now, int val, int k, int lim) { if(k < 0) return s[lat[now]] ^ val; int c = (val >> k) & 1; if(lat[trie[now][c ^ 1]] >= lim) return ask(trie[now][c ^ 1], val, k - 1, lim); else return ask(trie[now][c], val, k - 1, lim); }
int main() { n = rd(), m = rd(); lat[0] = -1; rt[0] = ++tot; add(0, 23, 0, rt[0]);
for(int i = 1; i <= n; ++i) { int x = rd(); s[i] = s[i - 1] ^ x; rt[i] = ++tot; add(i, 23, rt[i - 1], rt[i]); }
for(int i = 1; i <= m; ++i) { char opt; cin >> opt; if(opt == 'A') { int x = rd(); rt[++n] = ++tot; s[n] = s[n - 1] ^ x; add(n, 23, rt[n - 1], rt[n]); } else { int l = rd(), r = rd(), x = rd(); printf("%d\n", ask(rt[r - 1], x ^ s[n], 23, l - 1)); } } return 0; }
|