题目链接: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的更多相关文章

  1. CodeForces 587 E.Duff as a Queen 线段树动态维护区间线性基

    https://codeforces.com/contest/587/problem/E 一个序列, 1区间异或操作 2查询区间子集异或种类数 题解 解题思路大同小异,都是利用异或的性质进行转化,st ...

  2. 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 ...

  3. 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 ...

  4. *Codeforces587E. Duff as a Queen

    $n \leq 200000$的序列,支持以下$q \leq 4e4$个操作:区间异或$k$:查询区间能异或出多少不同的数.数字$0 \leq a_i \leq 1e9$. 大概是要区间线性基.区间修 ...

  5. cf Round 587

    A.Duff and Weight Lifting(思维) 显然题目中只有一种情况可以合并 2^a+2^a=2^(a+1).我们把给出的mi排序一下,模拟合并操作即可. # include <c ...

  6. CF数据结构练习

    1. CF 438D The Child and Sequence 大意: n元素序列, m个操作: 1,询问区间和. 2,区间对m取模. 3,单点修改 维护最大值, 取模时暴力对所有>m的数取 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 伪分布式hadoop启动后jps查不到namenode的解决办法

    启动过程没有发现错误,但是jps查看进程时,发现少了NameNode,而DataNode却存在: 原因: 是端口9000已经被占用,解决办法有两个, 第一种:查找占用端口的进程,kill掉它. had ...

  2. 使用 jQuery 调用 ASP.NET AJAX Page Method

    文章来源:http://chungle.iteye.com/blog/406054 说到轻量级的客户端通信,我注意到大多数人喜欢使用 ASP.NET AJAX Page Method 多于 ASMX ...

  3. mybatis mapper-locations作用

    application上配置了@MapperScan(扫面mapper类的路径)和pom.xml中放行了mapper.xml后,配置mapper-locations没有意义 查找后得知,如果mappe ...

  4. SQL[Err]ORA-00932: inconsistent datatypes: expected NUMBER got CHAR:

    ORA-00932: inconsistent datatypes: expected NUMBER got CHAR: 获取的目标类型与源类型不一致,多出现在case when 语句中,when的结 ...

  5. 记录常用的adb命令

    1.启动adb服务 adb start-server 2.关闭服务 adb kill-server 3.进入shell环境 adb shell 4.安装应用 adb install -r xxx.ap ...

  6. mybatis BindingException: Invalid bound statement (not found)

    错误截图 解决措施 此异常的原因是由于mapper接口编译后在同一个目录下没有找到mapper映射文件而出现的. 通常我们在配置SqlSessionFactory时会有如配置 <!-- 配置Sq ...

  7. JDBC 和连接池

    1 JDBC概述 Java DataBase Connectivity,Java数据库连接,一种执行SQL的Java API,为多种关系数据库提供统一访问规范,由一组Java语言编写的类和接口组成.数 ...

  8. Sysinternals Utilities

    https://docs.microsoft.com/zh-cn/sysinternals/ Sysinternals 之前为Winternals公司提供的免费工具,Winternals原本是一间主力 ...

  9. 外网无法ip访问服务器解决方法 (原)

    示例ip:119.75.1.1      windows server示例 一.检查网络是否通畅     打开dos窗口(windows+r , 输入cmd回车  )输入命令: ping 119.75 ...

  10. 《linux就该这么学》第六节,计划任务和用户身份管理!

    课本笔记:          case条件测试语句 4.4:计划任务服务 at 设置一次性计划任务 at  时间    //设置执行的任务                              a ...