设a[i]为前缀和,则i~j的异或和为a[j]^a[i],对于2个只需把另一个当成后缀就可以了

求max(a[j]^a[i])的话就用tire维护就可以了

 1 #include<bits/stdc++.h>
 2 #define inc(i,l,r) for(int i=l;i<=r;i++)
 3 #define dec(i,l,r) for(int i=l;i>=r;i--)
 4 #define link(x) for(edge *j=h[x];j;j=j->next)
 5 #define mem(a) memset(a,0,sizeof(a))
 6 #define inf 1e9
 7 #define ll long long
 8 #define succ(x) (1<<x)
 9 #define lowbit(x) (x&(-x))
10 #define NM 400000+5
11 using namespace std;
12 int read(){
13     int x=0,f=1;char ch=getchar();
14     while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
15     while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
16     return x*f;
17 }
18 const int m=31;
19 int n,a[NM],ans,_t,l[NM],r[NM];
20 struct node{
21     node *c[2];
22 }N[(m+1)*NM],*o=N,*root;
23 void ins(int x){
24     node *r=root;
25     dec(i,m,0){
26         int t=(1<<i)&x?1:0;
27         if(!r->c[t])r->c[t]=++o;
28         r=r->c[t];
29     }
30 }
31 int find(int x){
32     int s=0;node *r=root;
33     dec(i,m,0){
34         int t=(1<<i)&x?0:1;
35         if(r->c[t]){
36             s+=1<<i;
37             r=r->c[t];
38         }else r=r->c[t^1];
39     }
40     return s;
41 }
42 int main(){
43     freopen("data.in","r",stdin);
44     n=read();
45     inc(i,1,n)a[i]=read();
46     root=++o;ins(_t);
47     inc(j,1,n){
48     //    node *t=o;
49         _t^=a[j];
50         l[j]=max(l[j-1],find(_t));
51         ins(_t);
52     //    printf("%d ",o-N);
53     }
54     mem(N);root=o=N;_t=0;ins(_t);
55     dec(i,n,1){
56         _t^=a[i];
57         r[i]=max(r[i-1],find(_t));
58         ins(_t);
59     }
60     //inc(i,1,n)printf("%d ",l[i]);printf("\n");
61     //inc(i,1,n)printf("%d ",r[i]);printf("\n");
62     inc(i,1,n-1)ans=max(ans,l[i]+r[i+1]);
63     printf("%d\n",ans);
64     return 0;
65 }
View Code

 

posted on 2016-02-15 00:02  onlyRP  阅读(235)  评论(0编辑  收藏  举报