题目链接: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. 第k小整数

    题目描述: 现有n个正整数,n≤10000,要求出这n个正整数中的第k个最小整数(相同大小的整数只计算一次),k≤1000,正整数均小于30000. 输入: 第一行为n和k,第二行开始为n个正整数的值 ...

  2. Kruskal和prime算法的类实现,图的遍历BFS算法。

    一.图的遍历 #include<iostream> #include<queue> #include<vector> using namespace std; in ...

  3. [04-01]css组合选择器

    /* 私人笔记 */   组合选择器:把基本选择器通过特殊符号串在一起,可以带来一些特殊的意义: 1.源码 <!DOCTYPE html> <html lang="zh&q ...

  4. npm笔记

    #执行npm start时是运行的哪个js文件? 打开package.json看看scripts属性中start配置的是什么运行脚本,这里配置的就是你执行npm start时跑的脚本 #设置npm的源 ...

  5. 学习笔记:Makefile的ifeq逻辑或,逻辑与的变通实现

        (1)ifeq的用法 ifeq ($(变量名), 变量值 ) ........ else ifeq ($(..), ..) ......... else ......... endif (2) ...

  6. Win10部署IIS 10.0

    win10自带IIS10.0 控制面板 >> 程序 >>启用或关闭Windows功能 勾选完之后会安装IIS,安装完成后 计算机管理 >> 服务和应用程序 > ...

  7. Servlet 随记:

    API 1)init(ServletConfig config) 何时执行:servlet对象创建的时候执行 ServletConfig : 代表的是该servlet对象的配置信息 2)service ...

  8. python框架之Django(9)-CSRF

    准备 现有如下模板和视图: <!DOCTYPE html> <html lang="en"> <head> <meta charset=& ...

  9. python_的面向对象编程

    废话不多说,先弄个对象来看看 class Student(object): def __init__(self, name, score): self.name = name self.score = ...

  10. 最小生成树模板题 hpu 积分赛 Vegetable and Road again

    问题 H: Vegetable and Road again 时间限制: 1 Sec 内存限制: 128 MB 提交: 19 解决: 8 题目描述 修路的方案终于确定了.市政府要求任意两个公园之间都必 ...