【bzoj4260】Codechef REBXOR
来源:互联网 发布:知乎日报知乎好问题 编辑:程序博客网 时间:2024/06/11 11:13
Description
Input
输入数据的第一行包含一个整数N,表示数组中的元素个数。
第二行包含N个整数A1,A2,…,AN。
Output
输出一行包含给定表达式可能的最大值。
Sample Input
5
1 2 3 1 2
Sample Output
6
HINT
满足条件的(l1,r1,l2,r2)有:(1,2,3,3),(1,2,4,5),(3,3,4,5)。
对于100%的数据,2 ≤ N ≤ 4*105,0 ≤ Ai ≤ 109。
题解
记sum[i]表示1到i的xor和
l~r的异或和=sum[r] xor sum[l-1]
区间和变为两个值异或最大值,trie经典问题
代码
#include<bits/stdc++.h>typedef long long ll;using namespace std;inline int read(){ int x=0,f=1;char ch=getchar(); while (ch<'0'||ch>'9'){if (ch=='-')f=-1;ch=getchar();} while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}int t[6200005][2],l[400005],r[400005],n,tot,a[400005];inline void insert(int n){ int now=0; for (int i=30;i>=0;i--) { int x=(n>>i)&1; if (!t[now][x]) t[now][x]=++tot; now=t[now][x]; }}inline int query(int n){ int ans=0,now=0; for (int i=30;i>=0;i--) { int x=(n>>i)&1; if (t[now][!x]){ans+=1<<i;now=t[now][!x];} else now=t[now][x]; } return ans;}int main(){ n=read(); for (int i=1;i<=n;i++) a[i]=read(); insert(0); for (int i=1,now=0;i<=n;i++) { now^=a[i]; l[i]=max(l[i-1],query(now)); insert(now); } memset(t,0,sizeof(t));tot=0; insert(0); for (int i=n,now=0;i;i--) { now^=a[i]; r[i]=max(r[i+1],query(now)); insert(now); } int ans=0; for (int i=1;i<n;i++) ans=max(ans,l[i]+r[i+1]); cout<<ans; return 0;}
阅读全文
0 0
- [BZOJ4260] Codechef REBXOR
- 【BZOJ4260】Codechef REBXOR
- bzoj4260 Codechef REBXOR
- 【bzoj4260】【Codechef REBXOR】【trie】
- bzoj4260: Codechef REBXOR
- BZOJ4260 Codechef REBXOR trie
- 【bzoj4260】Codechef REBXOR
- 【bzoj4260】 Codechef REBXOR trie树
- [BZOJ4260][字典树]Codechef REBXOR
- 4260: Codechef REBXOR trie
- bzoj 4260 Codechef REBXOR
- 4260: Codechef REBXOR
- bzoj 4260: Codechef REBXOR
- Codechef REBXOR(01Trie)
- 【BZOJ 4260】 Codechef REBXOR|trie
- bzoj 4260: Codechef REBXOR Trie
- BZOJ 4260: Codechef REBXOR|Trie树
- BZOJ 4206 Codechef REBXOR 01字典树
- codeforces 572A Arrays
- python mysqldb 包编译后测试 警告
- 保存内容到本地(下载到本地)
- CURLE_WRITE_ERROR
- 10.21作业(Java)
- 【bzoj4260】Codechef REBXOR
- SpringBoot 中文手册 --Part IV --28 安全
- python3 time模块解释
- 测试
- 为何不用stop()和如何终止线程
- C# partial
- TomCat与Jvm关系
- c++primer第六章课后习题
- Java多线程下载框架01:多线程的好处以及断点续传原理