题目大意:
  给定一个长度为$n(n\leq10^5)$的数列$A$和数$k$$(A_i,k\leq10^6)$。$m$组询问,每次询问区间$[l,r]$中有多少对$i,j(l\leq i\leq j\leq r)$,满足$\oplus_{x=i}^jA_x=k$。

思路:
  莫队。
  首先求出数列$A$的前缀异或和$pre[i]$。每次加入一个数$x$时,$cnt[x]++$,$ans+=cnt[x\oplus k]$。删除同理。
  注意区间的范围,因为$\oplus_{x=i}^jA_x=pre[j]\oplus pre[i-1]$,所以对于询问$[l,r]$,实际维护的区间应该是$[l-1,r]$。

 #include<cmath>
#include<cstdio>
#include<cctype>
#include<algorithm>
typedef long long int64;
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'';
while(isdigit(ch=getchar())) x=(((x<<)+x)<<)+(ch^'');
return x;
}
const int N=,M=,logK=;
int k,a[N],bel[N],cnt[<<logK];
int64 ans[M],tmp;
struct Query {
int l,r,id;
bool operator < (const Query &another) const {
return bel[l]<bel[another.l]||(bel[l]==bel[another.l]&&bel[r]<bel[another.r]);
}
};
Query q[M];
inline void ins(const int &x) {
tmp+=cnt[a[x]^k];
cnt[a[x]]++;
}
inline void del(const int &x) {
cnt[a[x]]--;
tmp-=cnt[a[x]^k];
}
int main() {
const int n=getint(),m=getint(),block=sqrt(n);
k=getint();
for(register int i=;i<=n;i++) {
a[i]=a[i-]^getint();
bel[i]=i/block;
}
for(register int i=;i<m;i++) {
const int l=getint()-,r=getint();
q[i]=(Query){l,r,i};
}
std::sort(&q[],&q[m]);
for(register int i=,l=,r=-;i<m;i++) {
while(r<q[i].r) ins(++r);
while(l>q[i].l) ins(--l);
while(r>q[i].r) del(r--);
while(l<q[i].l) del(l++);
ans[q[i].id]=tmp;
}
for(register int i=;i<m;i++) {
printf("%lld\n",ans[i]);
}
return ;
}

[CF617E]XOR and Favorite Number/[CQOI2018]异或序列的更多相关文章

  1. CF617E XOR and Favorite Number

    CF617E XOR and Favorite Number 已知一个序列 \(a_1,\ a_2,\ \cdots,\ a_n\) 和 \(k\) ,\(m\) 次询问给出 \(l,\ r\) ,求 ...

  2. 题解-CF617E XOR and Favorite Number

    题面 CF617E XOR and Favorite Number 给定 \(n,m,k\) 和 \(n\) 个数的序列 \(a_i\),\(m\) 次求区间 \([l,r]\) 中异或值为 \(k\ ...

  3. bzoj 5301 [Cqoi2018]异或序列 莫队

    5301: [Cqoi2018]异或序列 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 204  Solved: 155[Submit][Status ...

  4. bzoj 5301: [Cqoi2018]异或序列 (莫队算法)

    链接:https://www.lydsy.com/JudgeOnline/problem.php?id=5301 题面; 5301: [Cqoi2018]异或序列 Time Limit: 10 Sec ...

  5. 「luogu4462」[CQOI2018] 异或序列

    「luogu4462」[CQOI2018]异或序列 一句话题意 输入 \(n\) 个数,给定\(k\),共 \(m\) 组询问,输出第 \(i\) 组询问 \(l_i\) \(r_i\) 中有多少个连 ...

  6. BZOJ5301: [Cqoi2018]异或序列(莫队)

    5301: [Cqoi2018]异或序列 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 400  Solved: 291[Submit][Status ...

  7. [bzoj5301][Cqoi2018]异或序列_莫队

    异或序列 bzoj-5301 Cqoi-2018 题目大意:题目链接. 注释:略. 想法: 由于a^a=0这个性质,我们将所有的数变成异或前缀和. 所求就变成了求所有的$l_i\le x<y\l ...

  8. XOR and Favorite Number Codeforces - 617E || [CQOI2018]异或序列

    https://www.luogu.org/problemnew/show/P4462 http://codeforces.com/problemset/problem/617/E 这个是莫队裸题了吧 ...

  9. BZOJ_5301_[Cqoi2018]异或序列&&CF617E_莫队

    Description 已知一个长度为 n 的整数数列 a[1],a[2],…,a[n] ,给定查询参数 l.r ,问在 [l,r] 区间内,有多少连续子 序列满足异或和等于 k . 也就是说,对于所 ...

随机推荐

  1. ASP.NET Core 2.1 源码学习之 Options[2]:IOptions 【转】

    原文链接:https://www.cnblogs.com/RainingNight/p/strongly-typed-options-ioptions-in-asp-net-core.html 在 上 ...

  2. Sprint 站立会议(个人)

    昨天做: 开Sprint会议确定并绘制Backlog. 今天做: 系统主窗体格局 编程环境搭建(部分) 遇到问题: 缺乏经验,没有好的总体规划. 团队博客园:http://www.cnblogs.co ...

  3. 【python】用python爬取中科院院士简介信息

    018/07/09 23:43 项目名称:爬取中科院871个院士的简介信息 1.爬取目的:中科院871个院士的简介信息 2.爬取最终结果: 3.具体代码如下: import re # 不用安装(注意! ...

  4. ajax-高设3

    ajax 1.XHR Ajax 技术的核心是 XMLHttpRequest 对象(简称 XHR),这是由微软首先引入的一个特性,其他浏览器提供商后来都提供了相同的实现.在 XHR 出现之前,Ajax ...

  5. css控制文字模糊

    *{ color: transparent; text-shadow: #111 0 0 5px; }

  6. js文字效果

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  7. BZOJ 1483:[HNOI2009]梦幻布丁(链表+启发式合并)

    [HNOI2009]梦幻布丁 Description N个布丁摆成一行,进行M次操作.每次将某个颜色的布丁全部变成另一种颜色的,然后再询问当前一共有多少段颜色.例如颜色分别为1,2,2,1的四个布丁一 ...

  8. java链接数据库--Mysql

    /************************************************************************* > File Name: Mysql.jav ...

  9. GYM - 101147 A.The game of Osho

    题意: 一共有G个子游戏,一个子游戏有Bi, Ni两个数字.两名玩家开始玩游戏,每名玩家从N中减去B的任意幂次的数,直到不能操作判定为输.问谁最终能赢. 题解: 当Bi为奇数的时候,显然Bi的所有次幂 ...

  10. poj1679 次最小生成树 kruskal(暴力枚举)

    Description Given a connected undirected graph, tell if its minimum spanning tree is unique. Definit ...