BZOJ3261 最大异或和 (可持久化Trie)
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)的更多相关文章
- bzoj3261: 最大异或和 可持久化trie
题意:给定一个非负整数序列{a},初始长度为N. 有M个操作,有以下两种操作类型: 1.Ax:添加操作,表示在序列末尾添加一个数x,序列的长度N+1. 2.Qlrx:询问操作,你需要找到一个位置p,满 ...
- BZOJ3261: 最大异或和(可持久化trie树)
题意 题目链接 Sol 设\(sum[i]\)表示\(1 - i\)的异或和 首先把每个询问的\(x \oplus sum[n]\)就变成了询问前缀最大值 可持久化Trie树维护前缀xor,建树的时候 ...
- 【bzoj3261】最大异或和 可持久化Trie树
题目描述 给定一个非负整数序列 {a},初始长度为 N. 有M个操作,有以下两种操作类型:1.A x:添加操作,表示在序列末尾添加一个数 x,序列的长度 N+1.2.Q l r x:询问操 ...
- BZOJ 3261: 最大异或和( 可持久化trie )
搞成前缀和然后就可以很方便地用可持久化trie维护了.时间复杂度O((N+M)*25) -------------------------------------------------------- ...
- [十二省联考2019]异或粽子——可持久化trie树+堆
题目链接: [十二省联考2019]异或粽子 求前$k$大异或区间,可以发现$k$比较小,我们考虑找出每个区间. 为了快速得到一个区间的异或和,将原序列做前缀异或和. 对于每个点作为右端点时,我们维护出 ...
- 洛谷.5283.[十二省联考2019]异或粽子(可持久化Trie 堆)
LOJ 洛谷 考场上都拍上了,8:50才发现我读错了题=-= 两天都读错题...醉惹... \(Solution1\) 先求一遍前缀异或和. 假设左端点是\(i\),那么我们要在\([i,n]\)中找 ...
- 【xsy1147】 异或(xor) 可持久化trie
我的脑回路可能比较奇怪. 我们对这些询问离线,将所得序列${a}$的后缀和建$n$棵可持久化$trie$. 对于一组询问$(l,r,x)$,我们在主席树上询问第$l$棵树$-$第r$+1$棵树中与$s ...
- [BZOJ4103][Thu Summer Camp 2015]异或运算 可持久化Trie树
4103: [Thu Summer Camp 2015]异或运算 Time Limit: 20 Sec Memory Limit: 512 MB Description 给定长度为n的数列X={x1 ...
- 【bzoj3689】异或之 可持久化Trie树+堆
题目描述 给定n个非负整数A[1], A[2], ……, A[n].对于每对(i, j)满足1 <= i < j <= n,得到一个新的数A[i] xor A[j],这样共有n*(n ...
- BZOJ 3261 最大异或和 可持久化Trie树
题目大意:给定一个序列,提供下列操作: 1.在数组结尾插入一个数 2.给定l,r,x,求一个l<=p<=r,使x^a[p]^a[p+1]^...^a[n]最大 首先我们能够维护前缀和 然后 ...
随机推荐
- iOS开发之——从零开始完成页面切换形变动画
前言 某天我接到了UI发给我的两张图: 需求图.png 看到图的时候我一脸懵逼,显然我需要做一个页面切换的指示动画.老实说,从大三暑假开始做iOS开发也一年有余了,但是遇到复杂动画总是唯恐避之不及,只 ...
- css清除浮动的处理方法
根据<精彩绝伦的css> <!DOCTYPE html> <html> <head> <meta charset="utf-8" ...
- visual studio 插件开发
插件的定义 所谓插件,就是根据平台接口开发的第三方程序.第一次听到这个名词很是不了解,听了解释也不是很明白,那我们来举个例子,比如说一辆房车,现在里面只有基本的一些设施,但是你现在想在顶部有一个晒太阳 ...
- linux 下crontabs使用
安装crontab:[root@CentOS ~]# yum install vixie-cron[root@CentOS ~]# yum install crontabs说明:vixie-cron软 ...
- ubuntu14.10设置开机启动服务
1.比如lampp其他的都类似: 我是这么操作:(屌丝初学者) a.把lampp启动程序放到/etc/bin下面 b.vi /etc/rc.local ,加入lampp start(有了第一步就可以这 ...
- Protocol Buffers in HBase
For early Hbase developers, it is often a nightmare to understand how the different modules speak am ...
- 一道数学题 hduacm 5144
题目大意: 一直初速度v和抛出速度h 求标枪抛出的最远距离: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5144 显然 d=v/g*sqrt( ...
- String类的写时拷贝
#include<iostream>using namespace std; class String;ostream& operator<<(ostream & ...
- sql 如何过滤重复记录
distinct : select distinct ID from table1
- mongo .update
db.classes.update({"count":{$gt:20}},{$set:{"name":"c4"}},false,false) ...