[BZOJ4260]Codechef REBXOR(Trie)
2018-11-01 17:33
381 查看
Trie模板题。求出每个前缀和后缀的最大异或和区间,枚举断点就可。不知为何跑得飞快。
#include<cstdio> #include<cstring> #include<algorithm> #define rep(i,l,r) for (int i=(l); i<=(r); i++) using namespace std; const int N=400010,M=N*30; int n,nd,x,ans,a ,pre ,suf ,ch[M][2]; void ins(int k){ int x=1; for (int i=30; ~i; i--){ if (!ch[x][(k>>i)&1]) ch[x][(k>>i)&1]=++nd; x=ch[x][(k>>i)&1]; } } int que(int k){ int x=1,res=0; for (int i=30; ~i; i--) if (ch[x][!((k>>i)&1)]) res|=1<<i,x=ch[x][!((k>>1)&1)]; else x=ch[x][(k>>i)&1]; return res; } int main(){ freopen("bzoj4260.in","r",stdin); freopen("bzoj4260.out","w",stdout); scanf("%d",&n); nd=1; ins(0); rep(i,1,n) scanf("%d",&a[i]); rep(i,1,n-1) x^=a[i],pre[i]=max(pre[i-1],que(x)),ins(x); memset(ch,0,sizeof(ch)); nd=1; ins(0); x=0; for (int i=n; i>1; i--) x^=a[i],suf[i]=max(suf[i+1],que(x)),ins(x); rep(i,1,n-1) ans=max(ans,pre[i]+suf[i+1]); printf("%d\n",ans); return 0; }
相关文章推荐
- BZOJ 4260 Codechef REBXOR 01Trie
- BZOJ4260 Codechef REBXOR trie
- bzoj 4260: Codechef REBXOR Trie
- 【BZOJ 4260】 Codechef REBXOR|trie
- [BZOJ]4260: Codechef REBXOR 可持久化Trie
- 【bzoj4260】【Codechef REBXOR】【trie】
- BZOJ4260 Codechef REBXOR(trie)
- 【BZOJ4260】 Codechef REBXOR 可持久化Trie
- BZOJ 4260: Codechef REBXOR( trie )
- BZOJ 4260: Codechef REBXOR 字典树
- BZOJ 4260 Codechef REBXOR 可持久化Trie树
- bzoj 4260: Codechef REBXOR
- [Bzoj4260]Codechef REBXOR(trie树)
- bzoj 4260: Codechef REBXOR
- [BZOJ4260] Codechef REBXOR
- BZOJ4260: Codechef REBXOR
- [BZOJ4260][字典树]Codechef REBXOR
- bzoj4260 Codechef REBXOR
- 4260: Codechef REBXOR trie
- bzoj 4260: Codechef REBXOR(01字典树)