[BZOJ3261] 最大异或和
2016-02-02 23:03
232 查看
传送门
http://www.lydsy.com/JudgeOnline/problem.php?id=3261题目大意
给定序列,支持一下两个操作1:在序列结尾插入一个数1:在序列结尾插入一个数
2:给定l,r,x,求一个l<=p<=r,使x xor a[p] xor a[p+1] xor ,..., xor a[n]最大2:给定l,r,x,求一个l<=p<=r,使x~~xor~~a[p]~~xor~~a[p+1]~~xor~~,...,~~xor~~a
最大
题解
可持久化Trie树裸题注意一点,x[0]要插入0,以x[-1]为空节点
const maxn=1000005; var x,root:array[0..maxn]of longint; son:array[0..30*maxn,0..1]of longint; size:array[0..30*maxn]of longint; i,j,k:longint; n,m,len1,len2,a,b,c:longint; cha:char; procedure init(pre,now,a:longint); var i,b,c:longint; begin size[now]:=size[pre]+1; for i:=29 downto 1 do begin if (a and (1<<(i-1)))=0 then b:=0 else b:=1; c:=b xor 1; son[now,c]:=son[pre,c]; inc(len2); son[now,b]:=len2; size[len2]:=size[son[pre,b]]+1; now:=son[now,b]; pre:=son[pre,b]; end; end; function query(l,r,a:longint):longint; var i,b,c,tt,val:longint; begin val:=0; for i:=29 downto 1 do begin if (a and (1<<(i-1)))=0 then b:=0 else b:=1; c:=b xor 1; tt:=size[son[r,c]]-size[son[l,c]]; if tt<>0 then begin l:=son[l,c]; r:=son[r,c]; inc(val,(1<<(i-1))); end else begin l:=son[l,b]; r:=son[r,b]; end; end; exit(val); end; begin readln(n,m); x[0]:=0; len1:=0; len2:=0; for i:=0 to n do begin if i<>0 then begin inc(len1); read(x[len1]); x[len1]:=x[len1-1] xor x[len1]; end; inc(len2); root[len1]:=len2; init(root[len1-1],root[len1],x[len1]); end; readln; for i:=1 to m do begin read(cha); if cha='A' then begin inc(len1); readln(x[len1]); x[len1]:=x[len1-1] xor x[len1]; inc(len2); root[len1]:=len2; init(root[len1-1],root[len1],x[len1]); end else begin readln(a,b,c); writeln(query(root[a-2],root[b-1],(x[len1] xor c))); end; end; end.
相关文章推荐
- poj2115
- 【很棒】Postfix使用介绍
- Day12~13(2016/2/1~2/2)
- 搭建个人页面的笔记
- vim学习笔记
- 引用的实质
- python教程2 安装使用 pycharm
- 局部光照模型及其BRDF
- 四、五版币冠字号发行量统计排行
- MongoDB_记录条数limit和跳过条数skip
- .Net and C# release history
- 推荐系统和搜索引擎的关系
- Linux管理-sed
- android程序的断点单步调试步骤
- hdu1811 Rank of Tetris(待解决 拓扑排序)
- 来年春天
- Unfinished List
- 阿里
- LeetCode 318. Maximum Product of Word Lengths (状态压缩)
- AlertDialog 用法大全