Codeforces 587 E. Duff as a Queen
题目链接:http://codeforces.com/contest/587/problem/E
其实就是线段树维护区间线性基,合并的时候注意一下。复杂度${O(nlog^{3})}$
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<cstring>
using namespace std;
#define maxn 100100
#define llg int
#define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
llg n,m,Q; inline int getint()
{
int w=,q=; char c=getchar();
while((c<'' || c>'') && c!='-') c=getchar(); if(c=='-') q=,c=getchar();
while (c>='' && c<='') w=w*+c-'', c=getchar(); return q ? -w : w;
} struct XOR
{
llg bas[],lazy,val; void init() {memset(bas,,sizeof(bas)); lazy=val=;} llg count()
{
llg ans=;
for (llg i=;i<=;i++) if (bas[i]) ans++;
return ans;
} void add(llg x)
{
for (llg i=;i>=;i--)
if ((x>>i)&)
{
if (bas[i]) x^=bas[i];
else {bas[i]=x; break;}
}
} XOR operator +(const XOR&a) const
{
XOR ans; ans.init();
for (llg i=;i<=;i++) ans.add(bas[i]),ans.add(a.bas[i]);
ans.add(a.val^val);
ans.val=val;
return ans;
}
}po[maxn*],ans; void pushdown(llg o,llg l,llg r)
{
llg lc=o<<,rc=o<<|;
if (po[o].lazy)
{
po[lc].lazy^=po[o].lazy;
po[rc].lazy^=po[o].lazy;
po[lc].val^=po[o].lazy;
po[rc].val^=po[o].lazy;
po[o].lazy=;
}
} void build(llg o,llg l,llg r)
{
po[o].init();
if (l==r)
{
po[o].val=getint();
return ;
}
llg lc=o<<,rc=o<<|,mid=(l+r)>>;
build(lc,l,mid);
build(rc,mid+,r);
po[o]=po[lc]+po[rc];
} void modify(llg o,llg l,llg r,llg L,llg R,llg d)
{
if (l>=L && r<=R)
{
po[o].lazy^=d;
po[o].val^=d;
return ;
}
pushdown(o,l,r);
llg lc=o<<,rc=o<<|,mid=(l+r)>>;
if (L<=mid) modify(lc,l,mid,L,R,d);
if (R>mid) modify(rc,mid+,r,L,R,d);
po[o]=po[lc]+po[rc];
} void query(llg o,llg l,llg r,llg L,llg R)
{
if (l>=L && r<=R)
{
ans=ans+po[o];
return ;
}
pushdown(o,l,r);
llg lc=o<<,rc=o<<|,mid=(l+r)>>;
if (L<=mid) query(lc,l,mid,L,R);
if (R>mid) query(rc,mid+,r,L,R);
po[o]=po[lc]+po[rc];
} int main()
{
yyj("xor");
cin>>n>>Q;
build(,,n);
while (Q--)
{
llg ty=getint(),l=getint(),r=getint();
if (ty==)
{
llg d=getint();
modify(,,n,l,r,d);
}
else
{
ans.init();
query(,,n,l,r);
printf("%d\n",(<<ans.count()));
}
}
return ;
}
Codeforces 587 E. Duff as a Queen的更多相关文章
- CodeForces 587 E.Duff as a Queen 线段树动态维护区间线性基
https://codeforces.com/contest/587/problem/E 一个序列, 1区间异或操作 2查询区间子集异或种类数 题解 解题思路大同小异,都是利用异或的性质进行转化,st ...
- Codeforces Round #549 (Div. 2)C. Queen
C. Queen time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...
- codeforces 587B B. Duff in Beach(dp)
题目链接: B. Duff in Beach time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- *Codeforces587E. Duff as a Queen
$n \leq 200000$的序列,支持以下$q \leq 4e4$个操作:区间异或$k$:查询区间能异或出多少不同的数.数字$0 \leq a_i \leq 1e9$. 大概是要区间线性基.区间修 ...
- cf Round 587
A.Duff and Weight Lifting(思维) 显然题目中只有一种情况可以合并 2^a+2^a=2^(a+1).我们把给出的mi排序一下,模拟合并操作即可. # include <c ...
- CF数据结构练习
1. CF 438D The Child and Sequence 大意: n元素序列, m个操作: 1,询问区间和. 2,区间对m取模. 3,单点修改 维护最大值, 取模时暴力对所有>m的数取 ...
- Codeforces Round #326 (Div. 2) D. Duff in Beach dp
D. Duff in Beach Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/588/probl ...
- Codeforces Round #326 (Div. 2) C. Duff and Weight Lifting 水题
C. Duff and Weight Lifting Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...
- Codeforces Round #326 (Div. 2) B. Duff in Love 分解质因数
B. Duff in Love Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/588/proble ...
随机推荐
- oracle的高级查询
1.简单连接 基本连接语法:SELECT [ALL|DISTINCT]column_name[,expression…]FROM table1_name[,table2_name,view_name, ...
- Mybatis连接配置文件详解
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE configurationPUBLIC &q ...
- mysql5.7 yum安装
1.在MySQL官网中下载YUM源rpm安装包:http://dev.mysql.com/downloads/repo/yum/ wget http://dev.mysql.com/get/mysql ...
- 洛谷P3384 【模板】树链剖分
题目描述 如题,已知一棵包含N个结点的树(连通且无环),每个节点上包含一个数值,需要支持以下操作: 操作1: 格式: 1 x y z 表示将树从x到y结点最短路径上所有节点的值都加上z 操作2: 格式 ...
- 通过阿里云命令行工具 aliyuncli 购买服务器
开始想通过 aliyuncli 的 golang 源码进行编译安装(注:python 版的 aliyuncli 已不再维护),但没成功,详见 通过 golang 源码编译阿里云命令行工具 aliyun ...
- Gym 101194D / UVALive 7900 - Ice Cream Tower - [二分+贪心][2016 EC-Final Problem D]
题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?opti ...
- 深入学习C#匿名函数、委托、Lambda表达式、表达式树类型——Expression tree types
匿名函数 匿名函数(Anonymous Function)是表示“内联”方法定义的表达式.匿名函数本身及其内部没有值或者类型,但是可以转换为兼容的委托或者表达式树类型(了解详情).匿名函数转换的计算取 ...
- java框架之SpringBoot(13)-检索及整合Elasticsearch
ElasticSearch介绍 简介 我们的应用经常需要使用检索功能,开源的 Elasticsearch 是目前全文搜索引擎的首选.它可以快速的存储.搜索和分析海量数据.SpringBoot 通过整合 ...
- spring datasource 使用 proxool
XmlWebApplicationContext使用的xml配置如下: <?xml version="1.0" encoding="UTF-8"?> ...
- Tomcat的日志分割三种方法
一.Tomcat的日志分割三种方法 一.方法一:用cronolog分割tomcat的catalina.out文件 Linux 日志切割工具cronolog详解:https://blog.csdn.ne ...