题目链接: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. linux中的pwd

    https://www.cnblogs.com/crazylqy/p/5818745.html

  2. easyui combobox 去空格事件 去掉,结果输入空格体验不畅的感觉,让combobox能够输入空格

    $("[comboname=name]").next("span").find("input.textbox-text").unbind(& ...

  3. JavaScript基础知识(DOM)

    获取元素的方法 要操作谁,就要先获取谁: 获取元素 1.document.getElementById:通过ID名来获取元素 兼容性: 在IE8以下,会默认把name属性当做id来获取: docume ...

  4. 微信小程序(微信应用号)组件讲解[申明:来源于网络]

    微信小程序(微信应用号)组件讲解[申明:来源于网络] 地址:http://www.cnblogs.com/muyixiaoguang/p/5902008.html

  5. LeetCode 788 Rotated Digits 解题报告

    题目要求 X is a good number if after rotating each digit individually by 180 degrees, we get a valid num ...

  6. Fiddler (进阶)内置命令与断点

    Fiddler 内置命令与断点 命令 对应请求项 介绍 示例 ? All 问号后边跟一个字符串,可以匹配出包含这个字符串的请求 ?google > Body 大于号后面跟一个数字,可以匹配出请求 ...

  7. 探究Java中的锁

    一.锁的作用和比较 1.Lock接口及其类图 Lock接口:是Java提供的用来控制多个线程访问共享资源的方式. ReentrantLock:Lock的实现类,提供了可重入的加锁语义 ReadWrit ...

  8. day014 模块

    # 1.用于多种语言交互 编程语言通用数据 # 内置的 不需要安装 直接导入使用 import json # 导入一个json模块 # dumps loads# dump load 有持久化的功能 # ...

  9. 转:C#中Undo/Redo的一个简易实现

    一个比较常见的改进用户体验的方案是用Redo/Undo来取代确认对话框,由于这个功能比较常用,本文简单的给了一个在C#中通过Command模式实现Redo/Undo方案的例子,以供后续查询. clas ...

  10. DIV层的使用方法

    1.可以判断你选择的样式是否存在用下边的方法(如果存在的话执行某个方法) if ($(this).hasClass('cur')) 2.这个方法可以查询一个页面中同样的div层总共有几个 var i= ...