可持久化$trie$树裸题,对于查询相当于查询$sum[p-1]space mathrm{xor} space sum[n] space mathrm{xor} space x$最大
把所有$sum$加入即可
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cstdlib> 5 #include<cmath> 6 #include<algorithm> 7 #include<queue> 8 #include<vector> 9 #include<map> 10 #include<set> 11 #define ll long long 12 #define db double 13 #define inf 2139062143 14 #define MAXN 600100 15 #define rep(i,s,t) for(register int i=(s),i##__end=(t);i<=i##__end;++i) 16 #define dwn(i,s,t) for(register int i=(s),i##__end=(t);i>=i##__end;--i) 17 #define ren for(register int i=fst[x];i;i=nxt[i]) 18 #define Fill(x,t) memset(x,t,sizeof(x)) 19 #define pls(a,b) (a+b)%MOD 20 #define mns(a,b) (a-b+MOD)%MOD 21 #define mul(a,b) (1LL*(a)*(b))%MOD 22 using namespace std; 23 inline int read() 24 { 25 int x=0,f=1;char ch=getchar(); 26 while(!isdigit(ch)) {if(ch=='-') f=-1;ch=getchar();} 27 while(isdigit(ch)) {x=x*10+ch-'0';ch=getchar();} 28 return x*f; 29 } 30 int n,m,tr[MAXN*26][2],rt[MAXN],val[MAXN*26],tot,sum; 31 void ins(int &k,int kk,int t,int x) 32 { 33 k=++tot,val[k]=val[kk]+1;if(t<0) return ;int i=(x>>t)&1;tr[k][!i]=tr[kk][!i]; 34 ins(tr[k][i],tr[kk][i],t-1,x); 35 } 36 int query(int k,int kk,int t,int x) 37 { 38 if(t<0) return 0;int i=(x>>t)&1;if(val[tr[k][!i]]>val[tr[kk][!i]]) 39 return (1<<t)+query(tr[k][!i],tr[kk][!i],t-1,x); 40 else return query(tr[k][i],tr[kk][i],t-1,x); 41 } 42 int main() 43 { 44 n=read(),m=read();ins(rt[0],0,25,0); 45 rep(i,1,n) sum^=read(),ins(rt[i],rt[i-1],25,sum); 46 char s[3];int a,b,c;while(m--) 47 { 48 scanf("%s",s);a=read(); 49 if(s[0]=='A') sum^=a,n++,ins(rt[n],rt[n-1],25,sum); 50 else 51 { 52 a=(a>1?rt[a-2]:0),b=read()-1,c=read(); 53 printf("%d ",query(rt[b],a,25,sum^c)); 54 } 55 } 56 }