【BZOJ】4260: Codechef REBXOR【Trie树】【前后缀异或最大】
4260: Codechef REBXOR
Time Limit: 10 Sec Memory Limit: 256 MB
Submit: 2218 Solved: 962
[Submit][Status][Discuss]
Description

.jpg)
Input
Output
Sample Input
1 2 3 1 2
Sample Output
HINT
Solution
用trie树处理出以$i$结尾的最大区间异或,前后分别扫一遍处理前缀和后缀。具体做法是将前缀或后缀插入trie树中,每次用前缀或后缀在trie树中查询异或最大,就是查询以$i$结尾的区间异或最大。
然后每个位置与前面取max,最后合并统计答案即可。
Code
#include<bits/stdc++.h>
using namespace std; int n, a[], l[], r[];
int son[*][], tail; void read(int &x) {
x = ; char ch = getchar();
while(ch > '' || ch < '') ch = getchar();
while(ch >= '' && ch <= '') {
x = x * + ch - '';
ch = getchar();
}
} void insert(int x) {
int nd = ;
for(int i = ; ~i; i --) {
int t = & (x >> i);
if(!son[nd][t]) son[nd][t] = ++ tail;
nd = son[nd][t];
}
} int query(int x) {
int nd = , ans = ;
for(int i = ; ~i; i --) {
int t = & (x >> i);
if(son[nd][!t]) {
ans += ( << i); nd = son[nd][!t];
} else if(son[nd][t]) nd = son[nd][t];
else break;
}
return ans;
} int main() {
read(n);
int now = ;
insert();
for(int i = ; i <= n; i ++) {
read(a[i]); now ^= a[i];
insert(now);
l[i] = query(now);
}
for(int i = ; i <= n; i ++) l[i] = max(l[i], l[i - ]);
now = ;
memset(son, , sizeof(son)); tail = ;
insert();
for(int i = n; i >= ; i --) {
now ^= a[i];
insert(now);
r[i] = query(now);
}
for(int i = n; i >= ; i --) r[i] = max(r[i], r[i + ]);
long long ans = ;
for(int i = ; i <= n; i ++)
ans = max(ans, 1ll * (l[i] + r[i + ]));
printf("%lld", ans);
return ;
}
【BZOJ】4260: Codechef REBXOR【Trie树】【前后缀异或最大】的更多相关文章
- bzoj 4260 Codechef REBXOR——trie树
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4260 一段的异或和就是两个前缀的异或和.正反扫两边,用trie树算每个位置为左/右端点时最大 ...
- BZOJ 4260: Codechef REBXOR (trie树维护异或最大值)
题意 分析 将区间异或和转化为前缀异或和.那么[L,R][L,R][L,R]的异或和就等于presum[R] xor presum[L−1]presum[R]\ xor \ presum[L-1]pr ...
- BZOJ 4260: Codechef REBXOR( trie )
求出前缀和, 那么以第x个元素结尾的最大异或值是max(sumx^sump)(1≤p<x), 用trie加速. 后缀同理, 然后扫一遍就OK了.时间复杂度O(31N) ------------- ...
- bzoj 4260: Codechef REBXOR (01 Trie)
链接: https://www.lydsy.com/JudgeOnline/problem.php?id=4260 题面: 4260: Codechef REBXOR Time Limit: 10 S ...
- 【BZOJ4260】Codechef REBXOR Trie树+贪心
[BZOJ4260]Codechef REBXOR Description Input 输入数据的第一行包含一个整数N,表示数组中的元素个数. 第二行包含N个整数A1,A2,…,AN. Output ...
- BZOJ 4260 Codechef REBXOR (区间异或和最值) (01字典树+DP)
<题目链接> 题目大意:给定一个序列,现在求出两段不相交的区间异或和的最大值. 解题分析: 区间异或问题首先想到01字典树.利用前缀.后缀建树,并且利用异或的性质,相同的两个数异或变成0, ...
- BZOJ 4260 Codechef REBXOR
Description Input 输入数据的第一行包含一个整数N,表示数组中的元素个数. 第二行包含N个整数A1,A2,…,AN. Output 输出一行包含给定表达式可能的最大值. Sample ...
- 【bzoj4260】Codechef REBXOR Trie树
题目描述 输入 输入数据的第一行包含一个整数N,表示数组中的元素个数. 第二行包含N个整数A1,A2,…,AN. 输出 输出一行包含给定表达式可能的最大值. 样例输入 5 1 2 3 1 2 样例输出 ...
- BZOJ 4260 Codechef REBXOR(字典树)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=4260 [题目大意] 给出一个数列,请找出两段连续且不相交的数段,使得其分别异或和的和 ...
- 【bzoj4260】 Codechef REBXOR trie树
Input 输入数据的第一行包含一个整数N,表示数组中的元素个数. 第二行包含N个整数A1,A2,…,AN. Output 输出一行包含给定表达式可能的最大值. Sample Input ...
随机推荐
- Sicily 1211. 商人的宣传
题目链接:http://soj.me/1211 Description Bruce是K国的商人,他在A州成立了自己的公司,这次他的公司生产出了一批性能很好的产品,准备宣传活动开始后的第L天到达B州进行 ...
- 如何和统计学家分享数据How to share data with a statistician
如何和统计学家分享数据 原文地址:https://github.com/jtleek/datasharing 将原文渣翻译的版本. 这是一份指南给需要分享数据给统计学家或者数据科学家的任何人.我认为的 ...
- vm tools安装包为空
新装了linux mint虚拟机之后突然发现安装vm tools时为空 1.关闭虚拟机2.打开设置 3.把CD/DVD(SATA)从安装系统时挂载的镜像改为自动检测 4.重启安装vm tools发现没 ...
- easyui表单提交验证form
方式一,不需要考虑jquery.easyui.min.js版本 <script> $(function () { //针对 设置 novalidate:true $('.validateb ...
- 实现checkebox全选取消操作
方法一: javascript代码: function checkedChild(obj,index){ var checkBoxs = document.getElementsByName(&quo ...
- Flask:cookie 和 session (0.1)
Windows 10家庭中文版,Python 3.6.4,Flask 1.0.2 Cookie是什么?有什么用? 某些网站为了辨别用户身份.进行 session 跟踪而储存在用户本地终端上的数据(通常 ...
- 应用服务器中对JDK的epoll空转bug的处理
原文链接:应用服务器中对JDK的epoll空转bug的处理 前面讲到了epoll的一些机制,与select和poll等传统古老的IO多路复用机制的一些区别,这些区别实质可以总结为一句话, 就是epol ...
- Ubuntu下apache2启动、停止、重启、配置
Linux系统为Ubuntu 一.Start Apache 2 Server /启动apache服务# /etc/init.d/apache2 startor$ sudo /etc/init.d/ap ...
- C++之插入迭代器
#include<iostream> #include<vector> #include<list> #include<iterator> usingn ...
- sqlserver中的全局变量总结
@@CONNECTIONS返回自上次启动 Microsoft? SQL Server? 以来连接或试图连接的次数.@@CPU_BUSY返回自上次启动 Microsoft? SQL Server? 以来 ...