BZOJ4260: Codechef REBXOR
Description

.jpg)
Input
Output
Sample Input
1 2 3 1 2
Sample Output
HINT
#include<cstdio>
#include<cctype>
#include<queue>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define ren for(int i=first[x];i;i=next[i])
using namespace std;
const int BufferSize=<<;
char buffer[BufferSize],*head,*tail;
inline char Getchar() {
if(head==tail) {
int l=fread(buffer,,BufferSize,stdin);
tail=(head=buffer)+l;
}
return *head++;
}
inline int read() {
int x=,f=;char c=Getchar();
for(;!isdigit(c);c=Getchar()) if(c=='-') f=-;
for(;isdigit(c);c=Getchar()) x=x*+c-'';
return x*f;
}
const int maxn=;
const int maxnode=;
int A[maxn],ch[maxnode][],ToT;
void insert(int val) {
int j=;
dwn(i,,) {
int c=val>>i&;
if(!ch[j][c]) ch[j][c]=++ToT;
j=ch[j][c];
}
}
int query(int val) {
int ans=,j=;
dwn(i,,) {
int c=val>>i&;
if(ch[j][c^]) j=ch[j][c^],ans|=<<i;
else j=ch[j][c];
}
return ans;
}
typedef long long ll;
int S[maxn],f[maxn],g[maxn];
int main() {
int n=read();
rep(i,,n) A[i]=read();
rep(i,,n) insert(S[i-]),f[i]=max(f[i-],query(S[i]=S[i-]^A[i]));
memset(ch,,sizeof(ch));ToT=;
dwn(i,n,) insert(S[i+]),g[i]=max(g[i+],query(S[i]=S[i+]^A[i]));
ll ans=;
rep(i,,n-) ans=max(ans,(ll)f[i]+g[i+]);
printf("%lld\n",ans);
return ;
}
BZOJ4260: Codechef REBXOR的更多相关文章
- [Bzoj4260]Codechef REBXOR(trie树)
4260: Codechef REBXOR Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 1534 Solved: 669[Submit][Stat ...
- [BZOJ4260]Codechef REBXOR(Trie)
Trie模板题.求出每个前缀和后缀的最大异或和区间,枚举断点就可.不知为何跑得飞快. #include<cstdio> #include<cstring> #include&l ...
- BZOJ4260 Codechef REBXOR(trie)
用trie求出前缀最大区间异或和.后缀最大区间异或和即可.注意空间是nlog的. #include<iostream> #include<cstdio> #include< ...
- BZOJ4260 Codechef REBXOR 题解
题目大意: 有一个长度为n的序列,求1≤l1≤r1<l2≤r2≤n使得(⊕r1i=l1ai)+(⊕r2i=l2ai)最大,输出这个最大值. 思路: 用Trie求出前缀异或和以及后缀异或和,再求出 ...
- BZOJ4260: Codechef REBXOR (01Tire树)
题意 题目链接 Sol 首先维护出前缀xor和后缀xor 对每个位置的元素插入到Trie树里面,每次找到和该前缀xor起来最大的元素 正反各做一遍,取最大. 记得要开log倍空间qwq.. #incl ...
- [BZOJ4260] Codechef REBXOR (01字典树,异或前缀和)
Description Input 输入数据的第一行包含一个整数N,表示数组中的元素个数. 第二行包含N个整数A1,A2,-,AN. Output 输出一行包含给定表达式可能的最大值. Sample ...
- 【BZOJ4260】Codechef REBXOR (Trie树)
[BZOJ4260]Codechef REBXOR (Trie树) 题面 BZOJ 题解 两眼题.第一眼不会做,第二眼好简单... 前缀异或和一下,拿\(Trie\)树维护求一个在这个端点以左的最大值 ...
- 【BZOJ4260】Codechef REBXOR Trie树+贪心
[BZOJ4260]Codechef REBXOR Description Input 输入数据的第一行包含一个整数N,表示数组中的元素个数. 第二行包含N个整数A1,A2,…,AN. Output ...
- 【BZOJ4260】 Codechef REBXOR 可持久化Trie
看到异或就去想前缀和(⊙o⊙) 这个就是正反做一遍最大异或和更新答案 最大异或就是很经典的可持久化Trie,从高到低贪心 WA: val&(1<<(base-1))得到的并不直接是 ...
随机推荐
- django 1.7 新特性 --- data migration
官方文档:https://docs.djangoproject.com/en/dev/topics/migrations/ 1.7 之前大家可能会用south用于管理数据库的模型的同步.1.7之后dj ...
- php中global与$GLOBALS的用法及区别
php中global 与 $GLOBALS[""] 差别 原本觉得global和$GLOBALS除了写法不一样觉得,其他都一样,可是在实际利用中发现2者的差别还是很大的! 先看下面 ...
- squid日志配置与轮询
squid日志分类及参数 SQUID默认的log文件非常多,其中最重要的LOG日志有三个,分别为access.log.store.log.cache.log.三个日志的记录的内容如下: access. ...
- sqlserver 常用语句
1.查询表中的RID RID=RowID=(fileID:pageID:slotID) SELECT sys.fn_PhysLocFormatter(%%physloc%%) AS rid,* FRO ...
- Windows 8操作技巧之快捷键大全
Windows 8操作系统发布之后,因为其新颖的界面和对触屏友好的设计,使许多长期使用Windows系统的用户,也觉得一时难以适应,一些操作方式也不知道如何去实现.在Windows系统中,快捷键无疑是 ...
- 【读书笔记】读《JavaScript模式》 - 函数复用模式之类式继承模式
实现类式继承的目标是通过构造函数Child()获取来自于另外一个构造函数Parent()的属性,从而创建对象. 1.类式继承模式#1 —— 默认方式(原型指向父函数实例) function Paren ...
- ubuntu 安装zabbix_agent端
root@(none):~# apt-get install zabbix-agent root@(none):~# vi /etc/zabbix/zabbix_agentd.conf Server= ...
- watchdog机制
转自:http://blog.sina.com.cn/s/blog_4dff871201012yzh.html 什么是Watchdog? Watchdog,又称watchdog timer,是计算机可 ...
- mac安装nginx
1,http://nginx.org/en/download.html下载http://nginx.org/download/nginx-1.2.0.tar.gz 2,tar -xf nginx-1. ...
- SQL 替换指定列中的指定字符串
Update 表名 Set 列名 = Replace(列名,‘被替换的字符’,‘要替换的字符’) Demo: UPDATE BPM_DailySET Workstation = REPLACE(Wor ...