题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4260

用 Trie 树可以找出前缀异或的最大值和后缀异或的最大值,拼起来即可;

注意要先加入一个0,表示区间左端点在 0 或右端点在 n+1;

竟然1A了!感动。

——然后发现3个月前做过!!!... https://www.cnblogs.com/Zinn/p/9301536.html

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int const xn=4e5+,mx=;
int n,cnt,a[xn],pr[xn],sc[xn],c[xn*mx][],bin[mx+];
int rd()
{
int ret=,f=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=; ch=getchar();}
while(ch>=''&&ch<='')ret=(ret<<)+(ret<<)+ch-'',ch=getchar();
return f?ret:-ret;
}
void init()
{
bin[]=;
for(int i=;i<=mx;i++)bin[i]=bin[i-]*;
}
void add(int x)
{
int nw=;
for(int i=mx;i>=;i--)
{
bool d=(x&bin[i]);
if(!c[nw][d])c[nw][d]=++cnt; nw=c[nw][d];
}
}
int query(int x)
{
int nw=,ret=;
for(int i=mx;i>=;i--)
{
bool d=!(x&bin[i]);
if(c[nw][d])nw=c[nw][d],ret+=bin[i];
else nw=c[nw][!d];
}
return ret;
}
int main()
{
n=rd(); init(); add();//
for(int i=,x,s=;i<=n;i++)
{
x=rd(); a[i]=x; s^=x;
pr[i]=max(pr[i-],query(s)); add(s);
}
cnt=; memset(c,,sizeof c); add();
for(int i=n,s=;i;i--)
{
s^=a[i];
sc[i]=max(sc[i+],query(s)); add(s);
}
int ans=;
for(int i=;i<n;i++)ans=max(ans,pr[i]+sc[i+]);
printf("%d\n",ans);
return ;
}

bzoj 4260 REBXOR —— Trie树的更多相关文章

  1. bzoj 4260: REBXOR Trie+乱搞

    题目大意: http://www.lydsy.com/JudgeOnline/problem.php?id=4260 题解: 啊啊啊. 被这种SB题坑了半天. 求出异或前缀和后 从n到1枚举\(r_1 ...

  2. bzoj 4260 Codechef REBXOR——trie树

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4260 一段的异或和就是两个前缀的异或和.正反扫两边,用trie树算每个位置为左/右端点时最大 ...

  3. BZOJ 4260: Codechef REBXOR (trie树维护异或最大值)

    题意 分析 将区间异或和转化为前缀异或和.那么[L,R][L,R][L,R]的异或和就等于presum[R] xor presum[L−1]presum[R]\ xor \ presum[L-1]pr ...

  4. 【BZOJ4260】Codechef REBXOR Trie树+贪心

    [BZOJ4260]Codechef REBXOR Description Input 输入数据的第一行包含一个整数N,表示数组中的元素个数. 第二行包含N个整数A1,A2,…,AN. Output ...

  5. bzoj4260 REBXOR——Trie树

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4260 对于每个位置,求一个前缀最大值和后缀最大值: 也就是从1到 i 的异或和要找前面某处的 ...

  6. 【bzoj4260】Codechef REBXOR Trie树

    题目描述 输入 输入数据的第一行包含一个整数N,表示数组中的元素个数. 第二行包含N个整数A1,A2,…,AN. 输出 输出一行包含给定表达式可能的最大值. 样例输入 5 1 2 3 1 2 样例输出 ...

  7. 【bzoj4260】 Codechef REBXOR trie树

    Input 输入数据的第一行包含一个整数N,表示数组中的元素个数. 第二行包含N个整数A1,A2,…,AN.     Output 输出一行包含给定表达式可能的最大值.   Sample Input ...

  8. BZOJ - 4260 01字典树+前后缀

    题意:给定\(a[1...n]\),求\((a_i⊕a_i+1⊕...⊕a_j)+(a_p⊕a_{p+1}⊕...⊕a_{q})\)的最大值,其中\(1≤i≤j<p≤q≤n\) 前后缀最优解预处 ...

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

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

随机推荐

  1. [Bzoj3172][Tjoi2013]单词(fail树)

    3172: [Tjoi2013]单词 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 4777  Solved: 2345[Submit][Status ...

  2. java验证身份证号码是否有效源代码 wn25的头像 wn25 23 2015-01-04 20:09 6 基本信息 Java × 1 浏览

    原文:http://www.open-open.com/code/view/1420373343171 1.描述 用java语言判断身份证号码是否有效,地区码.出身年月.校验码等验证算法 2.源代码 ...

  3. Invalid regular expression: unmatched parentheses

    Unmatched ) in Javascript regular expression您的某些字符串包含错误')'.你需要逃避这个.这是这样做的功能: function escapeRegExp(s ...

  4. yum gd linux

    32位操作系统安装命令:[root@localhost ~]# yum install php-gd*64位操作系统安装命令:[root@localhost ~]# yum install php-g ...

  5. linux下二机制文件的查看和编辑

    linux下很多命令都是二机制:/bin/下的各种命令---/bin/sh./bin/cat./bin/dmesg./bin/hostname等 如何查看这些二机制文件: xxd.hexdump 参考 ...

  6. flask如何使模板返回大文件,又不消耗大量内存

    当我们要往客户端发送大量的数据,比如一个大文件时,将它保存在内存中再一次性发到客户端开销很大.比较好的方式是使用流,本篇就要介绍怎么在Flask中通过流的方式来将响应内容发送给客户端.此外,我们还会演 ...

  7. Map与object的区别

    Map 对象保存键值对.任何值(对象或者原始值) 都可以作为一个键或一个值. 语法 new Map([iterable]) 参数 iterable Iterable 可以是一个数组或者其他 itera ...

  8. Git checkout on a remote branch does not work

    I believe this occurs when you are trying to checkout a remote branch that your local git repo is no ...

  9. [ACM] ZOJ 3725 Painting Storages (DP计数+组合)

    Painting Storages Time Limit: 2 Seconds      Memory Limit: 65536 KB There is a straight highway with ...

  10. IOS UIPickView+sqlite 选择中国全部城市案例

    1.案例简单介绍 通过读取文件.将中国全部城市写入sqlite数据库中,现通过UIPickView实现中国全部城市的选择,效果图例如以下所看到的 2.城市对象模型 中国全部城市数据请看http://b ...