BZOJ4260: Codechef REBXOR
Description
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))得到的并不直接是 ...
随机推荐
- BeautifulSoup获取指定class样式的div
如何获取指定的标签的内容是解析网页爬取数据的必要手段,比如想获取<div class='xxx'> ...<div>这样的div标签,通常有三种办法, 1)用字符串查找方法,然 ...
- Linux命令之exit - 退出当前shell【返回值状态】
原文链接:http://codingstandards.iteye.com/blog/836625 (转载请注明出处) 用途说明 exit命令用于退出当前shell,在shell脚本中可以终止当前 ...
- Having与Where的区别
where 子句的作用是在对查询结果进行分组前,将不符合where条件的行去掉,即在分组之前过滤数据,where条件中不能包含聚组函数,使用where条件过滤出特定的行. having 子句的作用是筛 ...
- Java for LeetCode 060 Permutation Sequence
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- DP:Wooden Sticks(POJ 1065)
摆木棍 题目大意:即使有一堆木棍,给一个特殊机器加工,木棍都有两个属性,一个是l一个是w,当机器启动的时候(加工第一根木棒的时候),需要一分钟,在这以后,设机器加工的上一根木棒的长度是l,质量是w,下 ...
- mybatis异常:Improper inline parameter map format. Should be: #{propName,attr1=val1,attr2=val2}问题分析及解决
转载自:http://blog.csdn.net/jackpk/article/details/44158701 mybatis异常:Improper inline parameter map for ...
- 获取4G以上的文件大小
1.DWORD dwFileSizeHigh; // 得到文件大小的高位 __int64 qwFileSize = GetFileSize(m_hSrcBigFile, &dwFileSi ...
- Docker跨主机通信之路由
一.实验环境: 主机名 主机IP Docker0_IP Docker1 192.168.88.130 172.17.0.1 Docker2 192.168.88.131 172.18.0.1 二.实验 ...
- Mysql 自动化任务
Mysql自动化任务,有两种:基于事件,基于时间. 基于事件,可由触发器来实现.具体触发器的编写比较简单,其语法规范可参照:http://www.jb51.net/article/59552.htm. ...
- Linux开发cocos2dx程序环境搭建
安装linux系统,ubuntu 14.04 64位 安装支持软件 sudo apt-get update sudo apt-get install git ssh vim ctags qt-sdk ...