#include #include #include using namespace std; const int maxn = 600010; int n, q, a[maxn], s[maxn], l, r, x; char op; struct Trie { int cnt, rt[maxn], ch[maxn * 33][2], val[maxn * 33]; void insert(int o, int lst, int v) { for (int i = 28; i >= 0; i--) { val[o] = val[lst] + 1; // 在原版本的基础上更新 if ((v & (1 << i)) == 0) { if (!ch[o][0]) ch[o][0] = ++cnt; ch[o][1] = ch[lst][1]; o = ch[o][0]; lst = ch[lst][0]; } else { if (!ch[o][1]) ch[o][1] = ++cnt; ch[o][0] = ch[lst][0]; o = ch[o][1]; lst = ch[lst][1]; } } val[o] = val[lst] + 1; // printf("%d\n",o); } int query(int o1, int o2, int v) { int ret = 0; for (int i = 28; i >= 0; i--) { // printf("%d %d %d\n",o1,o2,val[o1]-val[o2]); int t = ((v & (1 << i)) ? 1 : 0); if (val[ch[o1][!t]] - val[ch[o2][!t]]) ret += (1 << i), o1 = ch[o1][!t], o2 = ch[o2][!t]; // 尽量向不同的地方跳 else o1 = ch[o1][t], o2 = ch[o2][t]; } return ret; } } st; int main() { scanf("%d%d", &n, &q); for (int i = 1; i <= n; i++) scanf("%d", a + i), s[i] = s[i - 1] ^ a[i]; for (int i = 1; i <= n; i++) st.rt[i] = ++st.cnt, st.insert(st.rt[i], st.rt[i - 1], s[i]); while (q--) { scanf(" %c", &op); if (op == 'A') { n++; scanf("%d", a + n); s[n] = s[n - 1] ^ a[n]; st.rt[n] = ++st.cnt; st.insert(st.rt[n], st.rt[n - 1], s[n]); } if (op == 'Q') { scanf("%d%d%d", &l, &r, &x); l--; r--; if (l == 0) printf("%d\n", max(s[n] ^ x, st.query(st.rt[r], st.rt[0], s[n] ^ x))); else printf("%d\n", st.query(st.rt[r], st.rt[l - 1], s[n] ^ x)); } } return 0; }