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. 开发ActiveX控件调用另一个ActiveX系列3——ActiveX调用另一个ActiveX

    终于进入正题了,怎样在ActiveX中调用另一个ActiveX.我们的项目需要调用华视电子身份证识别仪的ActiveX控件 在这里有很多识别仪ActiveX插件下载:http://www.idukaq ...

  2. Java中的Enum的继承

    public interface Icolor{ int apply(int x,int y); } public enum color implements Icolor{ plus("+ ...

  3. NorFlash linux分区分析

    一般情况下,与板卡相关的内容都在bsp中(即arch/arm/mach-xxx/board-xxx.c)中,但norflash的分区直接放在norflash驱动中.由于norflash应用基于mtd, ...

  4. XJTU Summer Holiday Test 1(Divisibility by Eight-8的倍数)

    C - Divisibility by Eight Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  5. 【selenium+python】自动化测试目录与文件结构

    一.首先,看一下完整的项目目录结构图,如下: ==================目录结构================== ==================目录结构============== ...

  6. 理解cas

    前言 CAS(Compare and Swap),即比较并替换,实现并发算法时常用到的一种技术,Doug lea大神在java同步器中大量使用了CAS技术,鬼斧神工的实现了多线程执行的安全性. CAS ...

  7. leetCode 88.Merge Sorted Array (合并排序数组) 解题思路和方法

    Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note: Y ...

  8. Java&amp;Xml教程(十)XML作为属性文件使用

    我们一般会将Java应用的配置參数保存在属性文件里.Java应用的属性文件能够是一个正常的基于key-value对,以properties为扩展名的文件.也能够是XML文件. 在本案例中.將会向大家介 ...

  9. 帝国CMS万能标签ecmsinfo介绍

    带模板的信息调用标签:[万能标签](ecmsinfo) 标签名称: 带模板的信息调用标签 (sys_GetEcmsInfo) 格式:[ecmsinfo]栏目ID/专题ID, 显示条数, 标题截取数, ...

  10. IOS数组按中文关键字以字母序排序

    本文转载至 http://blog.csdn.net/xunyn/article/details/7882087 iosobjective cuser框架通讯 IOS项目中会用到对通讯录的联系人或是会 ...