RT 不知道为啥有一行格式炸了
#include <iostream>
#include <cstdio>
#include <algorithm>
const int N = 3e5+5;
int read(){
int x=0,f=1;
char ch = getchar();
while(ch<'0'||ch>'9'){
if(ch=='-'){
f = -1;
}
ch = getchar();
}
while(ch>='0'&&ch<='9'){
x = x*10+ch-'0';
ch = getchar();
}
return x*f;
}
struct aa{
int nums;
int ch[2];
}node[N*35*2];
int tot;
int qzh[N];
int root[N];
void add(int u,int v,int rk,int x){//u依附历史版本v
if(rk<0){
return;
}
int num = (x>>rk)&1;
node[u].ch[!num] = node[v].ch[!num];
node[u].ch[num] = ++tot;
node[node[u].ch[num]].nums = node[node[v].ch[num]].nums+1;
add(node[u].ch[num],node[v].ch[num],rk-1,x);
return;
}
int query(int u,int v,int rk,int x){
if(rk<0){
return 0;
}
int num = (x>>rk)&1;
if(node[node[v].ch[!num]].nums>node[node[u].ch[!num]].nums){
return (1<<rk)+query(node[u].ch[!num],node[v].ch[!num],rk-1,x);
}else{
return query(node[u].ch[num],node[v].ch[num],rk-1,x);
}
}
using namespace std;
int main(){
int n,m,x,y,z;
char opt[5];
n = read();m = read();
root[0] = ++tot;
add(root[0],0,25,0);
for(int i=1;i<=n;i++){
x = read();
qzh[i] = (qzh[i-1] ^ x);
root[i] = ++tot;
add(root[i],root[i-1],25,qzh[i]);
}
for(int i=1;i<=m;i++){
scanf("%s",opt);
if(opt[0]=='A'){
x = read();
n++;
root[n] = ++tot;
qzh[n] = (qzh[n-1]^x);
add(root[n],root[n-1],25,qzh[n]);
}else{
x = read();y = read();z = read();
cout<<query(x-1==0?0:root[x-2],root[y-1],25,z^qzh[n])<<'\n';
}
}
return 0;
}
/*
5 5
2 6 4 3 6
A 1
Q 3 5 4
A 4
Q 5 7 0
Q 3 6 6
*/