Read problems statements in Mandarin and Russian. Translations in Vietnamese to be uploaded soon.

Nikitosh the painter has a 1-indexed array A of N elements. He wants to find the maximum value of expression

(A[l1] ⊕ A[l1 + 1] ⊕ ... ⊕ A[r1]) + (A[l2] ⊕ A[l2 + 1] ⊕ ... ⊕ A[r2]) where 1 ≤ l1 ≤ r1 < l2 ≤ r2 ≤ N.

Here, x ⊕ y means the bitwise XOR of x and y.

Because Nikitosh is a painter and not a mathematician, you need to help him in this task.

Input

The first line contains one integer N, denoting the number of elements in the array.

The second line contains N space-separated integers, denoting A1A2, ... , AN.

Output

Output a single integer denoting the maximum possible value of the given expression.

Constraints

  • 2 ≤ N ≤ 4*105
  • 0 ≤ Ai ≤ 109

Subtasks

  • Subtask 1 (40 points) : 2 ≤ N ≤ 104
  • Subtask 2 (60 points) : Original constraints

Example

Input:
5
1 2 3 1 2 Output:
6

Explanation

Choose (l1r1l2r2) = (1, 2, 3, 3) or (1, 2, 4, 5) or (3, 3, 4, 5).

很久之前做的一道Trie树搞异或的题啦。。。。

大致就是求一下前缀和后缀异或最大值然后更新答案就好了。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<cstring>
#define ll int
#define maxn 400005
using namespace std; long long ans=;
ll ci[];
struct Trie{
ll ch[maxn*][];
ll tot,rot; void ins(ll x){
ll now=rot;
for(int i=;i>=;i--){
ll c=(ci[i]&x)?:;
if(!ch[now][c]) ch[now][c]=++tot;
now=ch[now][c];
}
} ll find_max(ll x){
ll now=rot,alr=;
for(int i=;i>=;i--){
ll c=(ci[i]&x)?:;
if(ch[now][c^]) alr+=ci[i],now=ch[now][c^];
else now=ch[now][c];
}
return alr;
}
}tr; ll a[maxn],w[maxn],n;
ll lef[maxn],rig[maxn]; inline void init(){
ci[]=;
for(int i=;i<=;i++) ci[i]=ci[i-]<<;
tr.rot=tr.tot=;
} int main(){
init(); scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d",a+i),w[i]=a[i]^w[i-]; tr.ins();
for(int i=;i<=n;i++){
lef[i]=max(lef[i-],tr.find_max(w[i]));
tr.ins(w[i]);
} memset(tr.ch,,sizeof(tr.ch));
init(); for(int i=n;i;i--){
rig[i]=max(rig[i+],tr.find_max(w[i]));
tr.ins(w[i]);
} for(int i=;i<=n;i++) ans=max(ans,(long long)(lef[i]+rig[i])); printf("%lld\n",ans);
return ;
}

最新文章

  1. 如何在ASP.NET 5上搭建基于TypeScript的Angular2项目
  2. TBB 学习笔记
  3. MYSQL界面操作系统之phpMyAdmin
  4. 关于TCP传输速率的测量方法
  5. 控制GridView中字段的长度,规范数据
  6. Inno Setup入门(二)&mdash;&mdash;修改安装过程中的图片
  7. iptables禁止ping入
  8. 深度学习的2016: NIPS 2016速览
  9. Cocoapods安装过程
  10. RTMPdump(libRTMP)源代码分析 4: 连接第一步——握手(Hand Shake)
  11. LeetCode刷题专栏第一篇--思维导图&amp;时间安排
  12. 【转载】KETTLE集群搭建
  13. JSP动态页面技术
  14. 用MyEclipse JPA创建项目(三)
  15. 为什么说 LINQ 要胜过 SQL
  16. SSM框架之RestFul示例
  17. WPF实现的简单饼图
  18. # 20145314《信息安全系统设计基础》期中复习总结 Part B
  19. 牛客小白月赛4C——病菌感染
  20. Coconuts HDU - 5925 二维离散化 自闭了

热门文章

  1. API网关Kong部署和使用文档
  2. PAT团体程序设计大赛---(模拟)
  3. CentOS 6.4安装配置ldap
  4. 学习python类
  5. 数据结构之DFS与BFS
  6. jquery实现通用结构折叠面板效果
  7. jquery中的get和post、ajax有关返回值的问题描述
  8. vivo面试经验4(linux基本操作,最基本,必须得会!!)
  9. PCIe 中的Capability 结构的寻址
  10. bzoj 4569 [Scoi2016]萌萌哒 并查集 + ST表