E. XOR and Favorite Number

题目连接:

http://www.codeforces.com/contest/617/problem/E

Descriptionww.co

Bob has a favorite number k and ai of length n. Now he asks you to answer m queries. Each query is given by a pair li and ri and asks you to count the number of pairs of integers i and j, such that l ≤ i ≤ j ≤ r and the xor of the numbers ai, ai + 1, ..., aj is equal to k.

Input

The first line of the input contains integers n, m and k (1 ≤ n, m ≤ 100 000, 0 ≤ k ≤ 1 000 000) — the length of the array, the number of queries and Bob's favorite number respectively.

The second line contains n integers ai (0 ≤ ai ≤ 1 000 000) — Bob's array.

Then m lines follow. The i-th line contains integers li and ri (1 ≤ li ≤ ri ≤ n) — the parameters of the i-th query.

Output

Print m lines, answer the queries in the order they appear in the input.

Sample Input

6 2 3

1 2 1 1 0 3

1 6

3 5

Sample Output

7

0

Hint

题意

给你n个数,然后M次询问,问你l,r区间内有多少对数,使得a[i]^a[j] = k

题解:

无修改,而且可以知道[l,r]可以O(1)就出[l-1,r],[l,r+1],[l+1,r],[l,r-1]的数据的

所有很显然的莫队算法搞一搞就好了

直接大暴力,注意不能再带log,所以直接开数组存就好了

注意,数组得开大一点哦

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 120010; int a[maxn],pos[maxn];
long long ans,flag[5000000];
long long Ans[maxn];
int k;
struct query
{
int l,r,id;
}Q[maxn];
bool cmp(query a,query b)
{
if(pos[a.l]==pos[b.l])
return a.r<b.r;
return pos[a.l]<pos[b.l];
}
void Updata(int x)
{
ans+=flag[a[x]^k];
flag[a[x]]++;
}
void Delete(int x)
{
flag[a[x]]--;
ans-=flag[a[x]^k];
}
int main()
{
int n,m;
scanf("%d%d%d",&n,&m,&k);
int sz =ceil(sqrt(1.0*n));
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
pos[i]=(i-1)/sz;
}
for(int i=1;i<=n;i++)
a[i]^=a[i-1];
for(int i=1;i<=m;i++)
{
scanf("%d%d",&Q[i].l,&Q[i].r);
Q[i].id = i;
}
sort(Q+1,Q+1+m,cmp);
int l = 1,r = 0;
ans=0;
flag[0]=1;
for(int i=1;i<=m;i++)
{
int id = Q[i].id;
while(r<Q[i].r)
{
r++;
Updata(r);
}
while(l>Q[i].l)
{
l--;
Updata(l-1);
}
while(r>Q[i].r)
{
Delete(r);
r--;
}
while(l<Q[i].l)
{
Delete(l-1);
l++;
}
Ans[id]=ans;
}
for(int i=1;i<=m;i++)
printf("%lld\n",Ans[i]);
}

Codeforces Round #340 (Div. 2) E. XOR and Favorite Number 莫队算法的更多相关文章

  1. 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 ...

  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. 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 ...

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

    题目链接:http://codeforces.com/contest/617/problem/E 题目大意:有n个数和m次查询,每次查询区间[l, r]问满足ai ^ ai+1 ^ ... ^ aj ...

  5. Codeforces Round #340 (Div. 2) E. XOR and Favorite Number

    time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standa ...

  6. 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 ...

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

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

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

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

  9. [Codeforces Round #340 (Div. 2)]

    [Codeforces Round #340 (Div. 2)] vp了一场cf..(打不了深夜的场啊!!) A.Elephant 水题,直接贪心,能用5步走5步. B.Chocolate 乘法原理计 ...

随机推荐

  1. Delphi 异或,英文为exclusive OR,或缩写成xor

    异或,英文为exclusive OR,或缩写成xor 异或(xor)是一个数学运算符.它应用于逻辑运算.异或的数学符号为“⊕”,计算机符号为“xor”.其运算法则为: a⊕b = (¬a ∧ b) ∨ ...

  2. Selenium RC配置

    Selenium  RC: -----作者: 虫师 ========================================================================== ...

  3. DzzOffice结合office web Apps私有部署的实例

    很多朋友都想在自己使用的DzzOffice中,调用本地部署的office web Apps server. 下面我就直接从头到尾的将部署全部过程分享给大家. 准备条件:两台服务器,配置稍高点,以免卡顿 ...

  4. 【LeetCode】66 & 67- Plus One & Add Binary

    66 - Plus One Given a non-negative number represented as an array of digits, plus one to the number. ...

  5. 2014搜狗前端面经【A事业部】

    刚刚面完搜狗,有种莫名其妙的感觉,哪里莫名其妙呢?听我慢慢道来... 开始面试官就这简历,问了一些有的没的东西,都不深(好吧我承认之前的经历有点菜,没神马加分项啊). 后面开始技术面: 知识点1:JS ...

  6. <javascript搞基程序设计>笔记2015-9-25

    1.一元加减 var a=28; alert(--a); //27,先减后用 alert(a--); //27,先用后减 alert(a); //26, 2.位操作符 按位非(NOT):按位取反:符号 ...

  7. 谈layout_gravity和gravity的用法

      相信对于Android的初学者来说,大家都曾经被layout里这两个极其相似的属性迷惑过. 简单使用一下搜索工具,我们就不难找到下面这样的答案: layout_gravity 表示组件自身在父组件 ...

  8. Linux-sed用法(2)

    本文为转载,原地址为:http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2856901.html 简介 sed 是一种在线编辑器,它一次处理一行内 ...

  9. 不定高度的div背景或背景图片不显示问题

    在使用div+css进行网页布局时,如果外部div有背景颜色或者边框,而不设置其高度,在IE浏览器下显示正常.但是使用Firefox/opera浏览时却出现最外层Div的背景颜色和边框不起作用的问题. ...

  10. Tcl之group arguments

    1 doubel quotes This allows substitutions to occur within the quotations - or "interpolation&qu ...