题面
http://darkbzoj.tk/problem/4260
题解
#include<cstdio> #include<iostream> #include<cstring> #define ri register int #define N 400050 #define INF (1<<30) using namespace std; int n,L[N],R[N]; int a[N],sum1[N],sum2[N]; inline int dit(int x,int i){ if (x&(1<<i)) return 1; else return 0; } struct TRIE { int ch[N*30][2],tot; void init() {tot=0;} void clear() { for (ri i=0;i<=tot;i++) ch[i][0]=ch[i][1]=0; tot=0; } void insert(int x) { int now=0; for (ri i=30;i>=0;i--) { int d=dit(x,i); if (!ch[now][d]) ch[now][d]=++tot; now=ch[now][d]; } } int search(int x) { int ret=0,now=0; for (ri i=30;i>=0;i--) { int d=1^dit(x,i); if (ch[now][d]) now=ch[now][d],ret+=(1<<i); else now=ch[now][d^1]; } return ret; } } trie; int main(){ scanf("%d",&n); for (ri i=1;i<=n;i++) scanf("%d",&a[i]); for (ri i=1;i<=n;i++) sum1[i]=sum1[i-1]^a[i]; for (ri i=n;i>=1;i--) sum2[i]=sum2[i+1]^a[i]; trie.init(); trie.clear(); for (ri i=1;i<=n;i++) { trie.insert(sum1[i-1]); L[i]=trie.search(sum1[i]); L[i]=max(L[i],L[i-1]); } trie.clear(); for (ri i=n;i>=1;i--) { trie.insert(sum2[i+1]); R[i]=trie.search(sum2[i]); R[i]=max(R[i],R[i+1]); } long long ret=0; for (ri i=1;i<n;i++) if (L[i]+R[i+1]>ret) ret=L[i]+R[i+1]; cout<<ret<<endl; }