Codeforces Round #532 (Div. 2) F 线性基(新坑) + 贪心 + 离线处理
https://codeforces.com/contest/1100/problem/F
题意
一个有n个数组c[],q次询问,每次询问一个区间的子集最大异或和
题解
- 单问区间子集最大异或和,线性基能处理,但是这次多次询问,假如每次重新建立基向量会超时
- 考虑区间的优先级,假如我只插入不删除的话,区间的优先级和左端点没有关系
- 贪心一下,只保留后面插入的基,这样就可以离线解决询问,然后查询的时候需要判基的位置是不是在左端点后面
代码
#include<bits/stdc++.h>
#define ft first
#define se second
#define pii pair<int,int>
#define mk make_pair
#define MAXN 500005
using namespace std;
vector<pii>G[MAXN];
int c[MAXN],n,i,q,j,ans[MAXN],B[30],pos[30],l,r;
void add(int x,int p){
for(int i=20;i>=0;i--){
if(x>>i&&1){
if(!B[i]){
pos[i]=p;
B[i]=x;
}
if(p>pos[i])swap(p,pos[i]),swap(x,B[i]);
x^=B[i];
}
}
}
int main(){
cin>>n;
for(i=1;i<=n;i++)scanf("%d",&c[i]);
cin>>q;
for(i=1;i<=q;i++){
scanf("%d%d",&l,&r);
G[r].push_back(mk(i,l));
}
for(i=1;i<=n;i++){
add(c[i],i);
for(auto x:G[i]){
for(j=20;j>=0;j--){
if(pos[j]>=x.se)ans[x.ft]=max(ans[x.ft]^B[j],ans[x.ft]);
}
}
}
for(i=1;i<=q;i++)printf("%d\n",ans[i]);
}
Codeforces Round #532 (Div. 2) F 线性基(新坑) + 贪心 + 离线处理的更多相关文章
- Codeforces Round #548 (Div. 2) E 二分图匹配(新坑) or 网络流 + 反向处理
https://codeforces.com/contest/1139/problem/E 题意 有n个学生,m个社团,每个学生有一个\(p_i\)值,然后每个学生属于\(c_i\)社团, 有d天,每 ...
- Codeforces Round #485 (Div. 2) F. AND Graph
Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Descri ...
- Codeforces Round #486 (Div. 3) F. Rain and Umbrellas
Codeforces Round #486 (Div. 3) F. Rain and Umbrellas 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...
- Codeforces Round #532 (Div. 2)
Codeforces Round #532 (Div. 2) A - Roman and Browser #include<bits/stdc++.h> #include<iostr ...
- Codeforces Round #501 (Div. 3) F. Bracket Substring
题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...
- Codeforces Round #532 (Div. 2) 题解
Codeforces Round #532 (Div. 2) 题目总链接:https://codeforces.com/contest/1100 A. Roman and Browser 题意: 给出 ...
- Codeforces Round #499 (Div. 1) F. Tree
Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/p ...
- Codeforces Round #532 (Div. 2):F. Ivan and Burgers(贪心+异或基)
F. Ivan and Burgers 题目链接:https://codeforces.com/contest/1100/problem/F 题意: 给出n个数,然后有多个询问,每次回答询问所给出的区 ...
- Codeforces Round #532 (Div. 2) Solution
A. Roman and Browser 签到. #include <bits/stdc++.h> using namespace std; ]; int get(int b) { ]; ...
随机推荐
- getPageNumRange
<script> function getPageNumRange(pagenumstr) { var pages=pagenumstr.split(";"); pag ...
- 查询当前局域网下所有IP和物理网卡地址
WIN+R –> 打开cmd 键入 arp -a
- spreed&rest
ES6变化-spreed&rest … 展开&收集运算符: 此运算符在不同地方使用有不同的功效,可以从写和读两个角度考虑. 写:function test (…arg){}; test ...
- mui-H5获取当前手机通讯录
mui.plusReady(function() { // 扩展API加载完毕,现在可以正常调用扩展API plus.contacts.getAddressBook(plus.contacts.ADD ...
- UVALive 3942 Remember the Word
题意:给出一个由S个不同单词组成的字典和一个长字符串.把这个字符串分解成若干个单词的连接(单词可以重复 使用),有多少种方法? Sample Input abcd 4 a b cd ab Sample ...
- 云笔记项目-Spring事务学习-传播NEVER
接下来测试事务传播属性NEVER Service层 Service层中设置事务传播属性都为NEVER. LayerT层代码 package LayerT; import javax.annotatio ...
- Jenkins master slave设置遇到的坑以及解决办法
写好了selenium测试脚本,本地运行没问题,但是现在流行分布式运行,并行执行以显得高大上. 然而,装高大上是要付出代价的. Selenium Grid 已经完美实现分布式和并行了. 奈何现在会Je ...
- HDFS中将普通用户增加到超级用户组supergroup
- oracle数据库查询语句case的用法
实现功能: 1.先查询status=2的记录,如果查询到记录则返回第一条记录的Product_Name:2.如果查询不到status=2的记录,则判断status=1的记录是否存在,不存在则返回“请耐 ...
- POJ-2236.WireleseNetwork.(并查集)
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 43199 Accepted: 178 ...