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, ..., ajis equal to k.

Input

The first line of the input contains integers nm 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.

Example

Input
6 2 3
1 2 1 1 0 3
1 6
3 5
Output
7
0
Input
5 3 1
1 1 1 1 1
1 5
2 4
1 3
Output
9
4
4

Note

In the first sample the suitable pairs of i and j for the first query are: (1, 2), (1, 4), (1, 5), (2, 3), (3, 6), (5, 6), (6, 6). Not a single of these pairs is suitable for the second query.

In the second sample xor equals 1 for all subarrays of an odd length.

题意:

给定数列a[],和m个询问 Q(L,R),回答每个询问中有多少对(L<=i<=j<=R) ,使得异或为k。

异或转化为前缀和处理。然后就差不多交给分块处理了。

离线处理里比较好理解的一种,高中就会了,注意这里不多BB了。

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#define ll long long
using namespace std;
const int maxn=;
int a[maxn],pre[maxn],num[<<],n,m,k,sqrtn;
struct Query{
int id,l,r; ll ans;
}q[maxn];
bool cmp(const Query a,const Query b)
{
if(a.l/sqrtn==b.l/sqrtn) return a.r<b.r;
return a.l<b.l;
}
bool cmp2(const Query a,const Query b)
{
return a.id<b.id;
}
int main()
{
scanf("%d%d%d",&n,&m,&k);
sqrtn=(int)sqrt(n);
for(int i=;i<=n;i++) {
scanf("%d",&a[i]);
pre[i]=pre[i-]^a[i];
}
for(int i=;i<m;i++){
scanf("%d%d",&q[i].l,&q[i].r);
q[i].id=i;
}
sort(q,q+m,cmp);
int l=,r=;
num[pre[]]++;num[]++;
ll cur=(a[]==k?:);
for(int i=;i<m;i++)
{
while(r<q[i].r){
cur+=num[pre[r+]^k];
r++;
num[pre[r]]++;
}
while(l<q[i].l){
num[pre[l-]]--;
cur-=num[pre[l-]^k];
l++;
}
while(l>q[i].l){
cur+=num[pre[l-]^k];
num[pre[l-]]++;
l--;
}
while(r>q[i].r){
num[pre[r]]--;
cur-=num[pre[r]^k];
r--;
}
q[i].ans=cur;
}
sort(q,q+m,cmp2);
for(int i=;i<m;i++) printf("%lld\n",q[i].ans);
return ;
}

Codeforces617E XOR and Favorite Number(分块 异或)的更多相关文章

  1. [CF617E]XOR and Favorite Number/[CQOI2018]异或序列

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

  2. XOR and Favorite Number(莫队算法+分块)

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

  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. Codeforces617 E . XOR and Favorite Number(莫队算法)

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

  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. 题解-CF617E XOR and Favorite Number

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

  7. Codeforeces 617E XOR and Favorite Number(莫队+小技巧)

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

  8. FJNU 1153 Fat Brother And XOR(胖哥与异或)

    FJNU 1153 Fat Brother And XOR(胖哥与异或) Time Limit: 1000MS   Memory Limit: 257792K [Description] [题目描述] ...

  9. CF617E XOR and Favorite Number

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

随机推荐

  1. 笔记本WIFI卡简介

    1.Intel AC9560(CNVI) AC9260(pcie) 3165D2W(pcie) 2.Realtek瑞昱 RTL8822be(pcie) RTL8723BU(USB) 英特尔在300系主 ...

  2. [技术讨论]关于前几天公布的京东bug上的问题分析

    1.  起因 前两天我公布了一个京东微信端截取到的三张图.并简单阐述了这三张图中的bug发现过程: 有朋友的评价是图中这种,可实际上.他应该是没有看出来这个bug代表的内容有多少.今天心血来潮决定具体 ...

  3. Pandoc PDF 中文

    最近终于又决定(^_^)使用reStructuredText写文档了,输出PDF时的中文问题必须要解决下. 安装环境 sudo apt install texlive texlive-latex-ex ...

  4. ASP.NET数据库连接字符串的加密与解密

    ASP.NET web.config中,数据库连接字符串的加密与解密. 虽然不怎么新鲜,但相信还是有许多人不知道,好,不说废话,直接给方法:开始--->运行,输入cmd,接着输入以下内容 加密: ...

  5. IPv4(三)地址掩码

    回顾网络类型确定 回顾一下之前学过的如果确定IP地址网络号,这里先不考虑子网. 首先通过首个八位组字节规则很容易确定IP地址属于那个网络: 如果第1位是0,则是A类地址: 如果前两位是10,则是B类地 ...

  6. 平滑处理 - cvSmooth() 函数实现

    前言 平滑是图像处理中很重要的操作,其主要用途是降噪.Open CV 提供了 5 种不同的平滑方法:简单模糊,简单无缩放变换的模糊,中值模糊,高斯模糊和双边滤波,它们都通过函数 cvSmooth 实现 ...

  7. go module

    前言 go 1.5 引进了vendor管理工程依赖包,但是vendor的存放路径是在GOPATH底下,另外每个依赖还可以有自己的vendor,通常会弄得很乱,尽管dep管理工具可以将vendor平级化 ...

  8. EasyPlayerPro windows播放器在播放RTMP视频显示重复异常问题解决

    问题来源 2017.12.18 今日有杭州某教育领域客户反馈EasyPlayerPro在播放一个rtmp源时,画面显示异常的问题.截图如下: 问题复现 一番思考, 将显示格式改为D3D显示, 正常, ...

  9. 九度OJ 1161:Repeater(复制器) (递归)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1449 解决:508 题目描述: Harmony is indispensible in our daily life and no one ...

  10. 九度OJ 1058:反序输出 (基础题)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:8454 解决:3042 题目描述: 输入任意4个字符(如:abcd), 并按反序输出(如:dcba) 输入: 题目可能包含多组用例,每组用例 ...