题目大意:
  给定一个长度为$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. rabbitmq之rpc

    环境:windows或者Linux,python3.6,rabbitmq3.5要求: 可以对指定机器异步的执行多个命令 例子: >>:run "df -h" --hos ...

  2. Python学习-前台开发-JavaScript、Dom和jQuery

    JavaScript JavaScript是一门编程语言,浏览器内置了JavaScript语言的解释器,所以在浏览器上按照JavaScript语言的规则编写相应代码之,浏览器可以解释并做出相应的处理. ...

  3. 1099 Build A Binary Search Tree (30 分)(查找二叉树)

    还是中序遍历建树 #include<bits/stdc++.h> using namespace std; ; struct node { int data; int L,R; }s[N] ...

  4. 团队项目-任务分解[Alpha0]

    团队项目-任务分解[Alpha0] 标签(空格分隔): 团队博客 适用范围: 本文档 适用对象 团队全体成员 适用时间 alpha阶段第一周计划 10.24-10.28 适用内容 目标.分工.时长估计 ...

  5. vue vscode 开始

    E:\Html\4 Vue版>npm config set registry https://registry.npm.taobao.org E:\Html\4 Vue版>npm i &g ...

  6. Codeforces Round #386 (Div. 2) 746F(set的运用)

    题目大意 给出一个歌单(有n首歌),每个歌都有愉悦值和时间,你可以选择从第x首歌开始听(也就是选择连续的一段),并且你可以选择w首歌让它的时间减半,限制时间为k,求最大的愉悦值 首先我们需要贪心一下, ...

  7. [洛谷P3810]【模板】三维偏序(陌上花开)

    题目大意:有$n$个元素,第$i$个元素有三个属性$a_i,b_i,c_i$,设$f(i)=\sum\limits_{i\not = j}[a_j\leqslant a_i,b_j\leqslant ...

  8. POJ 1064 Cable master | 二分+精度

    题目: 给n个长度为l[i](浮点数)的绳子,要分成k份相同长度的 问最多多长 题解: 二分长度,控制循环次数来控制精度,输出也要控制精度<wa了好多次> #include<cstd ...

  9. 【转发】Build Squid with SSL Bump and ICAP Client

    原文文档:http://docs.diladele.com/administrator_guide_3_4/installation_and_removal/filtering_https.html ...

  10. POJ3680:Intervals(离散化+最大流最小费用)

    Intervals Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 9320   Accepted: 4014 题目链接:ht ...