题意:给定数列 \(a\) 和 \(k\) ,询问区间 \([l,r]\) 中有多少子区间满足异或和为 \(k\)。

莫队。我们可以记录前缀异或值 \(a_i\),修改时,贡献为 \(c[a_i\bigoplus k]\) 。

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#define R register int
using namespace std;
namespace Luitaryi {
inline int g() { R x=0,f=1;
register char s; while(!isdigit(s=getchar())) f=s=='-'?-1:f;
do x=x*10+(s^48); while(isdigit(s=getchar())); return x*f;
} const int N=100010;
int n,m,k,B,anss,a[N],c[N<<1],ans[N];
struct node { int l,r,id,pos;
inline bool operator < (const node& that) const
{return pos==that.pos?pos&1?r<that.r:r>that.r:pos<that.pos;}
}q[N];
inline void add(int x) {anss+=c[x^k],++c[x];}
inline void sub(int x) {--c[x],anss-=c[x^k];}
inline void main() {
n=g(),m=g(),k=g(); B=sqrt(n+1);
for(R i=1;i<=n;++i) a[i]=g()^a[i-1];
for(R i=1;i<=m;++i)
q[i].l=g()-1,q[i].r=g(),q[i].id=i,q[i].pos=q[i].l/B+1;
sort(q+1,q+m+1);
for(R i=1,l=1,r=0,LL,RR,id;i<=m;++i) {
LL=q[i].l,RR=q[i].r,id=q[i].id;
while(l<LL) sub(a[l++]); while(l>LL) add(a[--l]);
while(r<RR) add(a[++r]); while(r>RR) sub(a[r--]); ans[id]=anss;
} for(R i=1;i<=m;++i) printf("%d\n",ans[i]);
}
} signed main() {Luitaryi::main(); return 0;}

2019.11.25

最新文章

  1. Day 1:学习Windows Phone 使用 SQLite
  2. AngularJS中的表单验证
  3. Emit学习(2) - IL - 常用指令介绍
  4. jenkins 的 ProcessTreeKiller----无法启动子进程的解决办法
  5. 使用rownum对oracle分页
  6. easyui filebox 浏览图片
  7. 《HTML5高级程序设计》知识点概要(不涉及详细语法)
  8. JavaScript对象就是一组属性(方法)的集合
  9. php 深入理解addslashes函数
  10. 安卓数据存储(3):SQLite数据库存储
  11. java中protect属性用法总结
  12. tableView特色用法
  13. kingso_sort - Taocode
  14. Ubuntu13.04 安装Redmine
  15. Item 27: 明白什么时候选择重载,什么时候选择universal引用
  16. 025 hibernate悲观锁、乐观锁
  17. 1 Java中的时间类型
  18. C#-----字节数组(byte[])和字符串相互转换
  19. 剑指offer(9)变态跳台阶
  20. python(六)——基本数据类型介绍

热门文章

  1. 监听EF执行的sql语句及状态
  2. C#代码常用技巧
  3. treeMultiselect 去掉勾选项
  4. 14-3 SQL Server基本操作
  5. java之struts2之文件下载
  6. 广州CBC2019
  7. 可分离滤波器设计高斯滤波 CUDA程序优化, 实验记录
  8. jmeter进行压测的步骤
  9. UCOS内存管理
  10. 【hadoop】在eclipse上运行WordCount的操作过程