const maxn=;
len=;
var x,y,z,n,m,tot,lx,i:longint;
sum:array[..maxn] of longint;
rt:array[..maxn] of longint;
time,l,r:array[..maxn*len] of longint;
ch:char;
procedure insert(x:longint);inline;
var p,i:longint;
begin
rt[lx]:=tot+; p:=rt[lx-];
for i:=len downto do
begin
inc(tot); l[tot]:=l[p]; r[tot]:=r[p]; time[tot]:=time[p]+;
if (x and (<<(i-))) > then
begin
p:=r[p];
r[tot]:=tot+;
end else
begin
p:=l[p];
l[tot]:=tot+;
end;
end;
inc(tot); l[tot]:=l[p]; r[tot]:=r[p]; time[tot]:=time[p]+;
end;
function query(a,b,x:longint):longint;inline;
var ans,i:longint;
begin
ans:=;
for i:=len downto do
begin
if (x and (<<(i-))) > then
begin
if time[l[b]]>time[l[a]] then
begin
a:=l[a]; b:=l[b];
ans:=ans+<<(i-);
end
else
begin
a:=r[a]; b:=r[b];
end
end else
begin
if time[r[b]]>time[r[a]] then
begin
a:=r[a]; b:=r[b];
ans:=ans+<<(i-);
end
else
begin
a:=l[a]; b:=l[b];
end
end;
end;
exit(ans);
end;
begin
readln(n,m);
sum[]:=; lx:=;
insert();
for i:= to n do
begin
read(x);
inc(lx);
sum[lx]:=x xor sum[lx-];
insert(sum[lx]);
end;
readln;
for i:= to m do
begin
read(ch);
if ch='A' then
begin
readln(x);
inc(lx);
sum[lx]:=x xor sum[lx-];
insert(sum[lx]);
end else
begin
readln(x,y,z);
writeln(query(rt[x-],rt[y],z xor sum[lx]));
end;
end;
end.

BZOJ3261 最大异或和 (可持久化Trie)的更多相关文章

  1. bzoj3261: 最大异或和 可持久化trie

    题意:给定一个非负整数序列{a},初始长度为N. 有M个操作,有以下两种操作类型: 1.Ax:添加操作,表示在序列末尾添加一个数x,序列的长度N+1. 2.Qlrx:询问操作,你需要找到一个位置p,满 ...

  2. BZOJ3261: 最大异或和(可持久化trie树)

    题意 题目链接 Sol 设\(sum[i]\)表示\(1 - i\)的异或和 首先把每个询问的\(x \oplus sum[n]\)就变成了询问前缀最大值 可持久化Trie树维护前缀xor,建树的时候 ...

  3. 【bzoj3261】最大异或和 可持久化Trie树

    题目描述 给定一个非负整数序列 {a},初始长度为 N.       有M个操作,有以下两种操作类型:1.A x:添加操作,表示在序列末尾添加一个数 x,序列的长度 N+1.2.Q l r x:询问操 ...

  4. BZOJ 3261: 最大异或和( 可持久化trie )

    搞成前缀和然后就可以很方便地用可持久化trie维护了.时间复杂度O((N+M)*25) -------------------------------------------------------- ...

  5. [十二省联考2019]异或粽子——可持久化trie树+堆

    题目链接: [十二省联考2019]异或粽子 求前$k$大异或区间,可以发现$k$比较小,我们考虑找出每个区间. 为了快速得到一个区间的异或和,将原序列做前缀异或和. 对于每个点作为右端点时,我们维护出 ...

  6. 洛谷.5283.[十二省联考2019]异或粽子(可持久化Trie 堆)

    LOJ 洛谷 考场上都拍上了,8:50才发现我读错了题=-= 两天都读错题...醉惹... \(Solution1\) 先求一遍前缀异或和. 假设左端点是\(i\),那么我们要在\([i,n]\)中找 ...

  7. 【xsy1147】 异或(xor) 可持久化trie

    我的脑回路可能比较奇怪. 我们对这些询问离线,将所得序列${a}$的后缀和建$n$棵可持久化$trie$. 对于一组询问$(l,r,x)$,我们在主席树上询问第$l$棵树$-$第r$+1$棵树中与$s ...

  8. [BZOJ4103][Thu Summer Camp 2015]异或运算 可持久化Trie树

    4103: [Thu Summer Camp 2015]异或运算 Time Limit: 20 Sec  Memory Limit: 512 MB Description 给定长度为n的数列X={x1 ...

  9. 【bzoj3689】异或之 可持久化Trie树+堆

    题目描述 给定n个非负整数A[1], A[2], ……, A[n].对于每对(i, j)满足1 <= i < j <= n,得到一个新的数A[i] xor A[j],这样共有n*(n ...

  10. BZOJ 3261 最大异或和 可持久化Trie树

    题目大意:给定一个序列,提供下列操作: 1.在数组结尾插入一个数 2.给定l,r,x,求一个l<=p<=r,使x^a[p]^a[p+1]^...^a[n]最大 首先我们能够维护前缀和 然后 ...

随机推荐

  1. iOS开发几年了,你清楚OC中的这些东西么!!!?

    iOS开发几年了,你清楚OC中的这些东西么!!!? 前言 几年前笔者是使用Objective-C进行iOS开发, 不过在两年前Apple发布swift的时候,就开始了swift的学习, 在swift1 ...

  2. Codeforces Round #313 (Div. 2) C. Gerald's Hexagon

    C. Gerald's Hexagon time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. [转]C#取得内网IP、外网IP、客户端IP方法

    前言 在 Windows Form Application 里对于取得 IP Address 有内网.外网两种 IP Address ,如果只需要取得内网 IP Address ,可以透过使用 IPH ...

  4. linux 查看僵尸进程

    top -b -i -n 1 查看僵死进程命令 ps -A -o stat,ppid,pid,cmd | grep -e '^[Zz]' 查看apache 当前进程数 ps -ef | grep ht ...

  5. mysql创建PATH快捷

    1.使其临时生效 PATH=$PATH:/usr/local/mysql/bin 2.永久生效 编辑/etc/profile  添加第79列 然后source /etc/profile 3.输入命令m ...

  6. 老男孩linux高级架构 百度云盘下载

    关于Linux的资源我了解还是比较少的,因为我最讨厌用命令行了(那是我大学时代的阴影啊!).这个资源收集很久了一直没有分享出来,因为我对Linux的了解真的很少,不知道怎么去描述,但是今天分享出来我想 ...

  7. 使用BroadcastReceiver监听系统接收的短信

    import android.content.BroadcastReceiver;import android.content.Context;import android.content.Inten ...

  8. plsql快速选中一行的快捷键

    实际工作中,经常用到pl/sql,在sql window中,经常性的用到选中一行然后按F8执行这条sql语句.用鼠标选中一行不是特别方便.用快捷键就快多了. 1.使用home键(不是windows键奥 ...

  9. “Unable to execute dex: Multiple dex files”如何解决?

    遇到报错: [2014-02-13 17:27:03 - Dex Loader] Unable to execute dex: Multiple dex files define Lcom/kkdia ...

  10. HTTP协议的chunked编码

    一般情况HTTP的Header包含Content-Length域来指明报文体的长度.如: 有时候服务生成HTTP回应是无法确定消息大小的,比如大文件的下载,或者后台需要复杂的逻辑才能全部处理页面的请求 ...