题目链接

 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
} /********************************************************************/ const int maxn = 1e5+;
int n, m, k;
int a[maxn], belong[maxn];
ll ans[maxn], flag[maxn*]; //注意这里的flag 要大大大大
ll now; struct node{
int l, r;
int id;
}q[maxn]; bool cmp(node x, node y){
if(belong[x.l] == belong[y.l])
return x.r < y.r;
return belong[x.l] < belong[y.l];
} void Update(int x){
now += flag[a[x]^k];
flag[a[x]]++;
} void Delete(int x){
flag[a[x]]--;
now -= flag[a[x]^k];
} int main(){
n = read(); m = read(); k = read();
int sz = ceil(sqrt(n));
for(int i = ;i <= n;i++){
a[i] = read();
belong[i] = (i-)/sz;
}
//前缀异或
for(int i = ;i <= n;i++){
a[i] = a[i-]^a[i];
}
for(int i = ;i <= m;i++){
q[i].l = read(); q[i].r = read();
q[i].id = i;
}
sort(q+, q++m, cmp);
int l = , r = ;
now = ;
flag[] = ;
for(int i = ;i <= m;i++){
int id = q[i].id; //while里面的顺序是不能随意更改的
while(l < q[i].l){
Delete(l-);
l++;
}
while(l > q[i].l){
l--;
Update(l-);
}
while(r < q[i].r){
r++;
Update(r);
}
while(r > q[i].r){
Delete(r);
r--;
}
ans[id] = now;
}
for(int i = ;i <= m;i++){
cout << ans[i] << endl;
}
return ;
}

E. XOR and Favorite Number (莫队板子题)的更多相关文章

  1. CODEFORCES 340 XOR and Favorite Number 莫队模板题

    原来我直接学的是假的莫队 原题: Bob has a favorite number k and ai of length n. Now he asks you to answer m queries ...

  2. Codeforces Round #340 (Div. 2) E XOR and Favorite Number 莫队板子

    #include<bits/stdc++.h> using namespace std; <<; struct node{ int l,r; int id; }q[N]; in ...

  3. Codeforces617 E . XOR and Favorite Number(莫队算法)

    XOR and Favorite Number time limit per test: 4 seconds memory limit per test: 256 megabytes input: s ...

  4. Codeforces Round #340 (Div. 2) E. XOR and Favorite Number 莫队算法

    E. XOR and Favorite Number 题目连接: http://www.codeforces.com/contest/617/problem/E Descriptionww.co Bo ...

  5. codeforces 617E E. XOR and Favorite Number(莫队算法)

    题目链接: E. XOR and Favorite Number time limit per test 4 seconds memory limit per test 256 megabytes i ...

  6. Codeforces Round #340 (Div. 2) E. XOR and Favorite Number —— 莫队算法

    题目链接:http://codeforces.com/problemset/problem/617/E E. XOR and Favorite Number time limit per test 4 ...

  7. CodeForces - 617E XOR and Favorite Number 莫队算法

    https://vjudge.net/problem/CodeForces-617E 题意,给你n个数ax,m个询问Ly,Ry,  问LR内有几对i,j,使得ai^...^ aj =k. 题解:第一道 ...

  8. Codeforces 617E XOR and Favorite Number莫队

    http://codeforces.com/contest/617/problem/E 题意:给出q个查询,每次询问区间内连续异或值为k的有几种情况. 思路:没有区间修改,而且扩展端点,减小端点在前缀 ...

  9. E. XOR and Favorite Number 莫队 2038: [2009国家集训队]小Z的袜子(hose)

    一直都说学莫队,直到现在才学,训练的时候就跪了   T_T,其实挺简单的感觉.其实训练的时候也看懂了,一知半解,就想着先敲.(其实这样是不好的,应该弄懂再敲,以后要养成这个习惯) 前缀异或也很快想出来 ...

  10. SP3267 DQUERY - D-query 莫队板子题

    题意可见:https://www.luogu.com.cn/problem/SP3267 可在vj上提交:https://vjudge.net/problem/SPOJ-DQUERY 题意翻译 给出一 ...

随机推荐

  1. java 浮点数

    package precisenumber; //import java.util.*;public class PreciseNumber { public int fore; public int ...

  2. delphi2010\delphi XE7 开发及调试WebService 实例

    使用delphi已经10多年了,一直搞桌面程序开发,对Webservice一直很陌生,近来因工作需要,学习delphi开发WebService,担心遗忘,作此笔记. 特别感谢 中塑在线技术总监 大犇  ...

  3. (转)Java经典设计模式(2):七大结构型模式(附实例和详解)

    原文出处: 小宝鸽 总体来说设计模式分为三大类:创建型模式.结构型模式和行为型模式. 博主的上一篇文章已经提到过创建型模式,此外该文章还有设计模式概况和设计模式的六大原则.设计模式的六大原则是设计模式 ...

  4. hadoop学习之旅2

    集群搭建文档1.0版本 1. 集群规划 所有需要用到的软件: 链接:http://pan.baidu.com/s/1jIlAz2Y 密码:kyxl 2.0 系统安装 2.1 主机名配置 vi /etc ...

  5. codeforces B. Trees in a Row 解题报告

    题目链接:http://codeforces.com/problemset/problem/402/B 题目意思:给出n个数和公差k,问如何调整使得ai + 1 - ai = k.(1 ≤ i < ...

  6. div遮罩弹框口

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  7. 搜索算法 pots

    题目链接  点击打开链接 Pots Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Su ...

  8. Opencv— — image offset

    // define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...

  9. Java标准输入

    Java: import java.util.*; public class Main{ public static void main(String args[]){ Scanner cin = n ...

  10. [Codeforces 715C] Digit Tree

    [题目链接] https://codeforces.com/contest/715/problem/C [算法] 考虑点分治 一条路径(x , y)合法当且仅当 : d(x) * 10 ^ dep(x ...