Test instructions: You can collect the weights of two disjoint intervals, the interval weights are interval xor, ask these two weights and the maximum is how much
Analysis: A lot of different or most of the problems are the use of 01 dictionary tree Greedy, do this question when I forgot ... Finally, when you look at someone else's code, I think of this routine.
L[i], recording, from 1 to i the largest XOR interval weight,
R[i], record, maximum XOR or interval weights from I to n
So the two rounds are inserted, and then the query greedy on the line, inserted is the prefix and suffix of the XOR 2 binary sequence, from the big start (greedy)
Note: The Spit groove, in fact, are the routines, different or and seek the largest, often to use the dictionary tree for Greed
#include <cstdio>#include<iostream>#include<ctime>#include<vector>#include<cmath>#include<map>#include<queue>#include<algorithm>#include<cstring>using namespaceStd;typedefLong LongLL;Const intn=3e6+5;Const intm=1e5+5;Const intinf=0x3f3f3f3f;structnode{intnex[2];} P[n+M];intCNT;intNewNode () {++CNT; p[cnt].nex[0]=p[cnt].nex[1]=-1; returnCNT;}intX[m],a[m];voidInsertintPOS) { intnow=0; for(intI= -; i>=0;--i) { intCur= (x[pos]& (1<<i)) >0?1:0; if(p[now].nex[cur]==-1) P[now].nex[cur]=NewNode (); now=P[now].nex[cur]; }}intGetmax (intPOS) { intnow=0, ret=0; for(intI= -; i>=0;--i) { intCur= (x[pos]& (1<<i)) >0?1:0; if(p[now].nex[cur^1]!=-1) {ret+=(1<<i); now=p[now].nex[cur^1]; } Elsenow=P[now].nex[cur]; } returnret;}intL[m],r[m];intMain () {intN; while(~SCANF ("%d",&N)) {CNT=-1; NewNode (); Insert (0); for(intI=1; i<=n;++i) {scanf ("%d",&A[i]); X[i]= (x[i-1]^A[i]); L[i]=max (Getmax (i), l[i-1]); Insert (i); } r[n+1]=x[n+1]=0; CNT=-1; NewNode (); Insert (n+1); for(inti=n;i;--i) {X[i]= (x[i+1]^A[i]); R[i]=max (Getmax (i), r[i+1]); Insert (i); } LL ret=0; for(intI=1; i<n;++i) RET=max (ret,1ll*l[i]+1ll*r[i+1]); printf ("%lld\n", ret); } return 0;}
View Code
NEUOJ711 Alien Factory Dictionary tree + greedy