BZOJ2741:[FOTILE模拟赛]L
Description
Input
Output
Sample Input
1 4 3
0 1
0 1
4 3
Sample Output
7
7
HINT
N=12000,M=6000,x,y,Ai在signed longint范围内。
题解:
把元素数组aa替换为前缀异或和数组qz,则询问变成了指定区间内最大的两个元素异或和。
假如某个元素x已经确定,那么我们只要在区间中找到一个数y,使x xor y最大。
这可以用字典树在O(log)的复杂度内实现。因为是指定的一个区间,所以要采用可持久化字典树。
为了减少复杂度,采取分块的做法。
将n分为√n块,对于每块的第一个元素i,用a[i,j]表示i到j的区间中的最大连续异或和。
转移方式:a[i,j]:=max(a[i,j-1],qz[j]在[i,j-1]的字典树中的最大异或和)。
注意不要忘了以[i,j]异或和作为答案的情况(即qz[i-1]xor qz[j])。
预处理好a数组后,开始处理询问[l,r]。
找到第一个比l大的分块首元素i(i=k*√n+1),分情况讨论。
若r≥i,则答案为max(a[i,r],qz[l≤j≤i-1]在[j+1,r]的字典树中的最大异或和);
若r<i,则答案为max(qz[l≤j≤r]在[l,j-1]的字典树中的最大异或和),注意考虑以[l,j]异或和作为答案的情况(即qz[l-1]xor qz[j])。
代码:
uses math;
var
t:array[..,..,..]of longint;
a:array[..,..]of longint;
qz,aa:array[..]of longint;
r:array[..]of longint;
b:array[..]of longint;
i,ii,j,k,n,m,block,mm,cnt,x,y,ans:longint;
l,ll,rr:int64;
procedure cl(y,yy,z:longint);
var i:longint;
begin
if z=- then exit;
i:=x and( shl z);
if i> then
begin
inc(cnt); t[yy,]:=t[y,];
t[yy,,]:=cnt; t[yy,,]:=t[y,,]+;
cl(t[y,,],t[yy,,],z-); exit;
end;
inc(cnt); t[yy,]:=t[y,];
t[yy,i,]:=cnt; t[yy,i,]:=t[y,i,]+;
cl(t[y,i,],t[yy,i,],z-);
end;
function qq(y,yy,z:longint):longint;
var i:longint;
begin
if z=- then exit();
i:=x and( shl z);
if i> then
begin
if t[yy,,]-t[y,,]> then
exit(b[z]+qq(t[y,,],t[yy,,],z-));
exit(qq(t[y,,],t[yy,,],z-));
end;
if t[yy,,]-t[y,,]> then
exit(b[z]+qq(t[y,,],t[yy,,],z-));
exit(qq(t[y,,],t[yy,,],z-));
end;
begin
b[]:=;
for i:= to do b[i]:=b[i-]*;
readln(n,m);
for i:= to n do
begin
read(aa[i]); qz[i]:=aa[i] xor qz[i-]; x:=qz[i];
inc(cnt); r[i]:=cnt; cl(r[i-],cnt,);
end;
block:=trunc(sqrt(n)*1.5)+;
block:=min(n,block);
i:=;
while i<=n do
begin
inc(mm);
a[mm,i]:=aa[i];
for j:=i+ to n do
begin
x:=qz[j]; a[mm,j]:=max(a[mm,j-],x xor qz[i-]);
a[mm,j]:=max(a[mm,j],qq(r[i-],r[j-],));
end;
i:=i+block;
end;
for i:= to m do
begin
readln(ll,rr);
l:=max((ll+ans)mod n+,(rr+ans)mod n+);
ll:=min((ll+ans)mod n+,(rr+ans)mod n+);
k:=l; j:=ll; l:=;
while block*l+<=j do inc(l);
if block*l+<=k then
begin
ans:=a[l+,k]; l:=block*l;
for ii:=j to l do
begin
x:=qz[ii-];
ans:=max(ans,qq(r[ii-],r[k],));
end;
end else
begin
ans:=aa[j];
for ii:=j+ to k do
begin
x:=qz[ii]; ans:=max(ans,x xor qz[j-]);
ans:=max(ans,qq(r[j-],r[ii-],));
end;
end;
writeln(ans);
end;
end.
BZOJ2741:[FOTILE模拟赛]L的更多相关文章
- BZOJ2741 FOTILE模拟赛L(分块+可持久化trie)
显然做个前缀和之后变成询问区间内两个数异或最大值. 一种暴力做法是建好可持久化trie后直接枚举其中一个数查询,复杂度O(nmlogv). 观察到数据范围很微妙.考虑瞎分块. 设f[i][j]为第i个 ...
- 【BZOJ2741】【块状链表+可持久化trie】FOTILE模拟赛L
Description FOTILE得到了一个长为N的序列A,为了拯救地球,他希望知道某些区间内的最大的连续XOR和. 即对于一个询问,你需要求出max(Ai xor Ai+1 xor Ai+2 .. ...
- 【bzoj2741】[FOTILE模拟赛] L
Portal --> bzoj2741 Solution 突然沉迷分块不能自拔 考虑用分块+可持久化trie来解决这个问题 对于每一块的块头\(L\),预处理\([L,i]\)区间内的所有子区间 ...
- 【bzoj2741】[FOTILE模拟赛]L 可持久化Trie树+分块
题目描述 FOTILE得到了一个长为N的序列A,为了拯救地球,他希望知道某些区间内的最大的连续XOR和. 即对于一个询问,你需要求出max(Ai xor Ai+1 xor Ai+2 ... xor A ...
- BZOJ.2741.[FOTILE模拟赛]L(分块 可持久化Trie)
题目链接 首先记\(sum\)为前缀异或和,那么区间\(s[l,r]=sum[l-1]^{\wedge}sum[r]\).即一个区间异或和可以转为求两个数的异或和. 那么对\([l,r]\)的询问即求 ...
- bzoj 2741 [FOTILE模拟赛] L
Description 多个询问l,r,求所有子区间异或和中最大是多少 强制在线 Solution 分块+可持久化trie 1.对于每块的左端点L,预处理出L到任意一个i,[L,j] 间所有子区间异或 ...
- 【BZOJ2741】【FOTILE模拟赛】L 分块+可持久化Trie树
[BZOJ2741][FOTILE模拟赛]L Description FOTILE得到了一个长为N的序列A,为了拯救地球,他希望知道某些区间内的最大的连续XOR和. 即对于一个询问,你需要求出max( ...
- BZOJ2741: 【FOTILE模拟赛】L
2741: [FOTILE模拟赛]L Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 1170 Solved: 303[Submit][Status] ...
- bzoj 2741: 【FOTILE模拟赛】L 分塊+可持久化trie
2741: [FOTILE模拟赛]L Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 1116 Solved: 292[Submit][Status] ...
随机推荐
- Async_Study
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- POJ2406-Power Strings-KMP循环节/哈希循环节
Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc&quo ...
- UVA 10382 Watering Grass 贪心+区间覆盖问题
n sprinklers are installed in a horizontal strip of grass l meters long and w meters wide. Each spri ...
- Codeforces 1182A Filling Shapes
题目链接:http://codeforces.com/problemset/problem/1182/A 思路:n为奇数时不可能完全填充,ans = 0.发现若要完全填充,每俩列可产生俩种情况,所以为 ...
- Apache Solr 远程命令+XXE执行漏洞(CVE-2017-12629)
Apache Solr 最近有出了个漏洞预警,先复习一下之前的漏洞 命令执行 先创建一个listener,其中设置exe的值为我们想执行的命令,args的值是命令参数 POST /solr/demo/ ...
- 【2018ACM/ICPC网络赛】徐州赛区
呃.自闭了自闭了.我才不会说我写D写到昏天黑地呢. I Characters with Hash 题目链接:https://nanti.jisuanke.com/t/31461 题意:给你一个字符串 ...
- leetcode 题型 数据结构 解法 分类总结
第2章 线性表 2.1 数组 2.1.1 Remove Duplicates from Sorted Array 2.1.2 Remove Duplicates from Sorted Array I ...
- js正则表达式常见面试题
1 . 给一个连字符串例如:get-element-by-id转化成驼峰形式. var str = "get-element-by-id"; var reg = /-\w/g; / ...
- Centos7 pxe
yum install dnsmasq mv /etc/dnsmasq.conf /etc/dnsmasq.conf.backup # vim /etc/dnsmasq.conf interface= ...
- Android Studio Gradle无法获取pom文件
错误提示: Error:Execution failed for task ':app:lintVitalRelease'. > Could not resolve all artifacts ...