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. 简述什么是ajax、javascript、json、Jquery?

    什么是Javascript? 基于对象.解释型.事件驱动.脚本语言.封装在<script>标签中使用.弱类型.与浏览器交互执行 什么 是Ajax? ajax是一种编程模式.在客户端与服务器 ...

  2. 【Android开发-5】界面装修,五大布局你选谁

    前言:假设要开一家店,门店装修是非常重要的事情.有钱都请专门的建筑设计公司来设计装修,没钱的仅仅能自己瞎折腾.好不好看全凭自己的感觉.像Android开发.在移动端大家看到的界面视觉不咋滴,一般连打开 ...

  3. 【BZOJ3217】ALOEXT 替罪羊树+Trie树

    [BZOJ3217]ALOEXT Description taorunz平时最喜欢的东西就是可移动存储器了……只要看到别人的可移动存储器,他总是用尽一切办法把它里面的东西弄到手. 突然有一天,taor ...

  4. 宇视摄像机RTSP地址格式规则

    rtsp://{用户名}:{密码}@{ip}:{port}/video1/2/3,分别对应主/辅/三码流: 比如: rtsp://admin:admin@192.168.8.8:554/video1, ...

  5. Django Web开发指南笔记

    Django Web开发指南笔记 语句VS表达式 python代码由表达式和语句组成,由解释器负责执行. 主要区别:表达式是一个值,它的结果一定是一个python对象:如:12,1+2,int('12 ...

  6. detached HEAD state

    1 detached HEAD state指的是什么 正常情况下,HEAD指向一个branch,而branch又指向一个commit. detached HEAD state指的是HEAD指针没有指向 ...

  7. Eclipse中servlet显示无法导入javax.servlet包问题的解决方案

    项目名-->右键 Property-->选择 JavaBuild Path-->选择 Add External JARs-->选择 把servlet-api.jar的路径输入即 ...

  8. contenttype应用 , 缓存相关

    一. Django的contenttypes contenttypes 是Django内置的一个应用,可以追踪项目中所有 app和model 的对应关系,并记录在 django_content_typ ...

  9. EntityFramework codefirst

    一.Entity Framework 迁移命令(get-help EntityFramework) Enable-Migrations 启用迁移 Add-Migration 为挂起的Model变化添加 ...

  10. Django 后台管理 之登录和注销

    Session:     session是服务器端生成保存的一个键值对 , session内部机制依赖于cookie . 用户登录后返回给客户端一个随机字符串,客户端带着随机字符串访问服务器,用于验证 ...