用trie求出前缀最大区间异或和、后缀最大区间异或和即可。注意空间是nlog的。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int read()
{
int x=,f=;char c=getchar();
while (c<''||c>'') {if (c=='-') f=-;c=getchar();}
while (c>=''&&c<='') x=(x<<)+(x<<)+(c^),c=getchar();
return x*f;
}
#define N 400010
int n,a[N],pre[N],suf[N],trie[N<<][],cnt,ans;
void ins(int x)
{
int k=;
for (int j=;~j;j--)
{
if (!trie[k][(x&(<<j))>]) trie[k][(x&(<<j))>]=++cnt;
k=trie[k][(x&(<<j))>];
}
}
int query(int x)
{
int k=,s=;
for (int j=;~j;j--)
if (trie[k][(x&(<<j))==]) s|=<<j,k=trie[k][(x&(<<j))==];
else k=trie[k][(x&(<<j))>];
return s;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("bzoj4260.in","r",stdin);
freopen("bzoj4260.out","w",stdout);
const char LL[]="%I64d\n";
#else
const char LL[]="%lld\n";
#endif
n=read();
for (int i=;i<=n;i++) a[i]=a[i-]^read();
cnt=;memset(trie,,sizeof(trie));ins();
for (int i=;i<=n;i++)
{
pre[i]=max(pre[i-],query(a[i]));
ins(a[i]);
}
cnt=;memset(trie,,sizeof(trie));ins();
for (int i=n;i>=;i--)
{
suf[i]=max(suf[i+],query(a[i]));
ins(a[i]);
}
for (int i=;i<n;i++) ans=max(ans,pre[i]+suf[i+]);
cout<<ans;
return ;
}

BZOJ4260 Codechef REBXOR(trie)的更多相关文章

  1. [Bzoj4260]Codechef REBXOR(trie树)

    4260: Codechef REBXOR Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 1534  Solved: 669[Submit][Stat ...

  2. 【BZOJ4260】Codechef REBXOR (Trie树)

    [BZOJ4260]Codechef REBXOR (Trie树) 题面 BZOJ 题解 两眼题.第一眼不会做,第二眼好简单... 前缀异或和一下,拿\(Trie\)树维护求一个在这个端点以左的最大值 ...

  3. bzoj 4260: Codechef REBXOR (01 Trie)

    链接: https://www.lydsy.com/JudgeOnline/problem.php?id=4260 题面: 4260: Codechef REBXOR Time Limit: 10 S ...

  4. 【python】Leetcode每日一题-前缀树(Trie)

    [python]Leetcode每日一题-前缀树(Trie) [题目描述] Trie(发音类似 "try")或者说 前缀树 是一种树形数据结构,用于高效地存储和检索字符串数据集中的 ...

  5. LA3942-Remember the Word(Trie)

    题意: 有s个不同的单词,给出一个长字符串把这个字符串分解成若干个单词的连接(可重复使用),有多少种分解方法 分析: dp[i]表示i开始的字符串能分解的方法数 dp[i]=sum(dp[i+len( ...

  6. HDU 1671 Phone List (Trie)

    pid=1671">Phone List Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  7. 【BZOJ】4260: Codechef REBXOR【Trie树】【前后缀异或最大】

    4260: Codechef REBXOR Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 2218  Solved: 962[Submit][Stat ...

  8. hdu 1251 统计难题 (字典树(Trie)<PS:C++提交不得爆内存>)

    统计难题Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others)Total Submis ...

  9. [BZOJ4260]Codechef REBXOR(Trie)

    Trie模板题.求出每个前缀和后缀的最大异或和区间,枚举断点就可.不知为何跑得飞快. #include<cstdio> #include<cstring> #include&l ...

随机推荐

  1. 北京Uber优步司机奖励政策(1月25日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  2. 成都Uber优步司机奖励政策(1月18日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  3. 成都Uber优步司机奖励政策(1月13日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  4. gitignore 文件生效办法

    .gitignore 可以添加一些不加入git版本控制的文件 比如一些测试文件.因人而异的配置信息等等 .gitignore 文件展示如下 /.idea/target//.classpath /.pr ...

  5. Android开发-API指南-<permission-tree>

    <permission-tree> 英文原文:http://developer.android.com/guide/topics/manifest/permission-tree-elem ...

  6. python邮件服务-yagmail

      下载安装 yagmail import yagmail #链接邮箱服务器 #此处的password是授权码 yag= yagmail.SMTP( user="843092012@qq.c ...

  7. jquery datatable 常用例子

    在项目中经常用到DataTable,如果DataTable使用得当,不仅能使程序简洁实用,而且能够提高性能,达到事半功倍的效果,现对DataTable的使用技巧进行一下总结. 一.DataTable简 ...

  8. HADOOP docker(一):安装hadoop实验集群(略操蛋)

    一.环境准备 1.1.机器规划 主机名    别名    IP     角色 9321a27a2b91 hadoop1 172.17.0.10 NN1 ZK RM 7c3a3c9cd595 hadoo ...

  9. [C++] Class (part 2)

    Members that are const or reference must be initialized. Similary, members that are of a class type ...

  10. JavaScript中childNodes和children的区别

    我在学习JavaScript对DOM操作的过程中,发现了使用childNodes属性,得不到我想要的结果,因此我就从JavaScript高级程序设计中了解了childNodes和children的区别 ...