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 ...
随机推荐
- Nginx之使用nginx搭建简单的文件服务器
使用nginx可以搭建简单文件服务器 安装nginx(不详述) 修改配置文件 /usr/local/nginx/conf/nginx.conf user root; /usr/local/nginx/ ...
- RabbitMQ的几个概念
VHost:虚拟主机,不同的VHost之间完全隔离,互不干扰.类似我们使用VM创建的多个虚拟机.创建好VHost之后需要我们指定其所有者.创建方式:RabbitMQ管理控制台 - Admin → Vi ...
- listview添加数据
1. 添加数据: ListView1.ViewStyle:=vsReport; ListView1.Columns.Add; ListView1.Columns[0].Caption:='aaaa'; ...
- Centos7下搭建LAMP环境,安装wordpress(不会生产博客,只是一名博客搬运工)(菜鸟)
1.搭建MySQL数据库 安装MariaDB yum install mariadb-server -y 启动MySQL服务 emctl start mariadb #启动服务 emtcl enabl ...
- 【托业】新托业全真题库---TEST1
clearly indicate ——clearly可以修饰indicate(表明:暗示:指示) recently只用于现在完成时和过去完成时中 municipal gallery 市立美术馆 per ...
- 5、Flutter 实现 ViewPager、bottomNavigationBar 界面切换
1.前言 首先我们想一下,如果在 Android 中实现 布局切换,通常的思路是: 做一个 viewpager 一组 Fragment 每个 Fragment 绑定一个 xml 最后填充至 viewp ...
- linux 单次定时任务
使用at =======查看当前任务========= at -l 或者atq =======查看任务执行什么===== at -c =======配置任务========= at 02:00 ...
- C# Tuple<T1,T2....T>元组的使用
1) 先说组元:一个数据结构,由通过逗号分割的,用于传递给一个程序或者操作系统的一系列值的组合. NET Framework 直接支持一至七元素的元组 Tuple<T1> Tuple< ...
- #WEB安全基础 : HTTP协议 | 0x7 学会使用wireshark分析数据包
wireshark是开源,免费,跨平台的抓包分析工具 我们可以通过wireshark学习HTTP报文和进行抓包分析,在CTF中的流量分析需要用到抓包 1.下载和安装 这是wireshark的官网 ht ...
- linux 创建用户和添加到组
1.添加用户 先用root用户登录 useradd -m testuser #这样的做会在/home下创建目录 2.指定shell #cat /etc/passwd #查看用户指定shell roo ...