Cramming ...
The first thought of finding the difference or value of the K-large can be determined by the method similar to the balance tree to check the K large
Then, just run to the prefix and go up dead knock ...
However, obviously one can be durable trie tree can be solved ...
Then n*p*32^2 after the show how so slow,,, and then found that others are n*p*32, every time to write down the good, do not run again ...
1#include <bits/stdc++.h>2 using namespacestd;3 #defineMP Make_pair4 #defineFIR First5 #defineSEC Second6 #defineMAXN 10057 #defineMAXM 3000058 #defineMaxnd 100000059 #defineMAXL 32Ten intA[MAXN],B[MAXM]; One intnd,root[maxm],trie[maxnd][2],mrk[maxnd]; Apair<int,int>AT[MAXN]; - intRead () { - inttmp=0;CharCh=0; the while(ch<'0'|| Ch>'9') ch=GetChar (); - while(ch>='0'&&ch<='9') tmp=tmp*Ten+ch-'0', ch=GetChar (); - returntmp; - } + voidInsertintPOS) { - intx=++nd,y=root[pos-1]; +root[pos]=x; A for(inti=maxl-1; i>=0; i--){ at intVal= (b[pos]>>i) &1; -trie[x][val^1]=trie[y][val^1]; -mrk[x]=mrk[y]+1; -trie[x][val]=++nd; -x=trie[x][val],y=Trie[y][val]; - } inmrk[x]=mrk[y]+1; - } to intSolveintUintDintLintRintk) { + intans=0; - for(intj=u;j<=d;j++) theAT[J]=MP (root[r],root[l-1]); * for(inti=maxl-1; i>=0; i--){ $ intCnt=0;Panax Notoginseng for(intj=u;j<=d;j++){ - intVal= (a[j]>>i) &1; thecnt+=mrk[trie[at[j].fir][val^1]]-mrk[trie[at[j].sec][val^1]]; + } A if(cnt>=k) { theans+=1<<i; + for(intj=u;j<=d;j++){ - intVal= (a[j]>>i) &1; $AT[J]=MP (trie[at[j].fir][val^1],trie[at[j].sec][val^1]); $ } - } - Else{ thek-=CNT; - for(intj=u;j<=d;j++){Wuyi intVal= (a[j]>>i) &1; theat[j]=MP (Trie[at[j].fir][val],trie[at[j].sec][val]); - } Wu } - } About returnans; $ } - intMain () { - intn,m,q,u,d,l,r,k; -N=read (), m=read (); A for(intI=1; i<=n;i++) a[i]=read (); + for(intI=1; i<=m;i++){ theb[i]=read (); - Insert (i); $ } theq=read (); the for(intI=1; i<=q;i++){ theU=read (), D=read (), L=read (), R=read (), k=read (); theprintf"%d\n", Solve (u,d,l,r,k)); - } in return 0; the}
View Code
[BZOJ4103] XOR operation