BZOJ4260: Codechef REBXOR (01Tire树)
题意
Sol
首先维护出前缀xor和后缀xor
对每个位置的元素插入到Trie树里面,每次找到和该前缀xor起来最大的元素
正反各做一遍,取最大。
记得要开log倍空间qwq。。
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 4e5 + 10;
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-')f =- 1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N, a[MAXN], s[MAXN], pmx[MAXN], smx[MAXN], ch[MAXN][2], tot;
void insert(int x) {
int now = 0;
for(int i = 0; i <= 30; i++) {
int nxt = (x >> i & 1);
if(!ch[now][nxt]) ch[now][nxt] = ++tot;
now = ch[now][nxt];
}
}
int Query(int x) {
int now = 0, ans = 0;
for(int i = 0; i <= 30; i++) {
int nxt = (x >> i & 1);
if(ch[now][nxt ^ 1]) ans += 1 << i, now = ch[now][nxt ^ 1];
else now = ch[now][nxt];
}
return ans;
}
void solve(int *s, int *mx) {
for(int i = 1; i <= N; i++) {
s[i] = s[i - 1] ^ a[i];
insert(s[i]);
mx[i] = Query(s[i]);
mx[i] = max(mx[i - 1], mx[i]);
}
}
int main() {
//freopen("3.in", "r", stdin);
N = read();
for(int i = 1; i <= N; i++) a[i] = read();
solve(s, pmx);
reverse(a + 1, a + N + 1);
solve(s, smx);
reverse(smx + 1, smx + N + 1);
int ans = 0;
for(int i = 1; i <= N; i++) ans = max(ans, pmx[i] + smx[i + 1]);
cout << ans;
}
BZOJ4260: Codechef REBXOR (01Tire树)的更多相关文章
- 【BZOJ4260】Codechef REBXOR Trie树+贪心
[BZOJ4260]Codechef REBXOR Description Input 输入数据的第一行包含一个整数N,表示数组中的元素个数. 第二行包含N个整数A1,A2,…,AN. Output ...
- [Bzoj4260]Codechef REBXOR(trie树)
4260: Codechef REBXOR Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 1534 Solved: 669[Submit][Stat ...
- 【bzoj4260】Codechef REBXOR Trie树
题目描述 输入 输入数据的第一行包含一个整数N,表示数组中的元素个数. 第二行包含N个整数A1,A2,…,AN. 输出 输出一行包含给定表达式可能的最大值. 样例输入 5 1 2 3 1 2 样例输出 ...
- [BZOJ4260] Codechef REBXOR (01字典树,异或前缀和)
Description Input 输入数据的第一行包含一个整数N,表示数组中的元素个数. 第二行包含N个整数A1,A2,-,AN. Output 输出一行包含给定表达式可能的最大值. Sample ...
- 【bzoj4260】 Codechef REBXOR trie树
Input 输入数据的第一行包含一个整数N,表示数组中的元素个数. 第二行包含N个整数A1,A2,…,AN. Output 输出一行包含给定表达式可能的最大值. Sample Input ...
- BZOJ4260: Codechef REBXOR
Description Input 输入数据的第一行包含一个整数N,表示数组中的元素个数. 第二行包含N个整数A1,A2,…,AN. Output 输出一行包含给定表达式可能的最大值. S ...
- [BZOJ4260]Codechef REBXOR(Trie)
Trie模板题.求出每个前缀和后缀的最大异或和区间,枚举断点就可.不知为何跑得飞快. #include<cstdio> #include<cstring> #include&l ...
- BZOJ4260 Codechef REBXOR(trie)
用trie求出前缀最大区间异或和.后缀最大区间异或和即可.注意空间是nlog的. #include<iostream> #include<cstdio> #include< ...
- bzoj 4260 Codechef REBXOR——trie树
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4260 一段的异或和就是两个前缀的异或和.正反扫两边,用trie树算每个位置为左/右端点时最大 ...
随机推荐
- CI框架源码学习笔记4——Benchmark.php
我们回到Codeigniter.php上继续往下看,第一个引入的类文件是Benchmark.php,这个文件主要是提供基准测试,具体使用方法参考手册http://codeigniter.org.cn/ ...
- ABAP开发常见任务
在ABAP开发中 最主要的工作: 1 报表的开发 主要使用到数据库读取 ALV LIST等技术: 2 单据的打印 主要使用到数据库读取.SmartFirms.Form等技术: 3 数据的上载 主要使用 ...
- Codeforces Round #549 div2 1143-B Nirvana 题解
Kurt reaches nirvana when he finds the product of all the digits of some positive integer. Greater v ...
- CF1101E Polycarp's New Job
#include<iostream> #include<cstdio> #include<algorithm> #include<cstdlib> #i ...
- 4.Single Number(出现一次的数)
Level: Easy 题目描述: Given a non-empty array of integers, every element appears twice except for one. ...
- sqlmap用法
用法 Usage: python sqlmap.py [options] Options: -h, --help Show basic help message and exit -hh Show a ...
- 商品录入功能v1.0【持续优化中...】
# 录入商品 def goods_record(): print("欢迎使用铜锣辉的购物商城[商品管理][录入商品]".center(30, "*")) whi ...
- pytorch 检测图片中是否有人
照搬pytorch官方代码,只是将数据集换成了INRIAPerson数据集中的train和test文件夹. 贴下代码和效果,代码是官方的,就不详细解释了. # License: BSD # Autho ...
- doors dxl 遍历object 查找
Module m = current; //m = edit(“xxx”) Object o for o in m do { string sht = o.”shtName” Buffer bf=cr ...
- Html背景图
<table style="height: 210px;" ><tbody><tr><td style="background- ...