Constmaxn=600008; Len= -;varX,y,z,n,m,tot,lx,i:longint; Sum:Array[0.. MAXN] ofLongint; RT:Array[0.. MAXN] ofLongint; Time,l,r:Array[0.. Maxn*len] ofLongint; Ch:char;procedureInsert (x:longint); inline;varP,i:longint;beginRT[LX]:=tot+1; p:=rt[lx-1]; forI:=lenDownto 1 Do beginInc (TOT); L[tot]:=L[P]; R[TOT]:=R[P]; time[tot]:=time[p]+1; if(x and(1<< (I-1))) >0 Then beginP:=R[p]; R[tot]:=tot+1; End Else beginP:=L[p]; L[tot]:=tot+1; End; End; Inc (TOT); L[tot]:=L[P]; R[TOT]:=R[P]; time[tot]:=time[p]+1;End;functionquery (a,b,x:longint): Longint;inline;varAns,i:longint;beginans:=0; forI:=lenDownto 1 Do begin if(x and(1<< (I-1))) >0 Then begin ifTime[l[b]]>time[l[a]] Then beginA:=l[a]; b:=L[b]; Ans:=ans+1<< (I-1); End Else beginA:=r[a]; C +R[b]; End End Else begin ifTime[r[b]]>time[r[a]] Then beginA:=r[a]; C +R[b]; Ans:=ans+1<< (I-1); End Else beginA:=l[a]; C +L[b]; End End; End; Exit (ANS);End;beginreadln (n,m); sum[0]:=0; lx:=1; Insert (0); fori:=1 toN Do beginread (x); Inc (LX); SUM[LX]:=x XOR sum[lx-1]; Insert (SUM[LX]); End; READLN; fori:=1 toM Do beginread (CH); ifCh='A' Then beginreadln (x); Inc (LX); SUM[LX]:=x XOR sum[lx-1]; Insert (SUM[LX]); End Else beginreadln (x, y, z); Writeln (Query (rt[x-1],rt[y],z xor SUM[LX]); End; End;End.
BZOJ3261 Maximum xor (persistent trie)