CoderForces-617B
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 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.
Example
6 2 3
1 2 1 1 0 3
1 6
3 5
7
0
5 3 1
1 1 1 1 1
1 5
2 4
1 3
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.
题意:这道题意思为:给你一行数,让你查找在这行数中有多少子区间满足其内的数亦或为K;
题解:可以让sum[i]表示从1亦或到i的值;sum[i]^=sum[i-1];
sum[r]=k^sum[l-1];(l,r分别表示左右端点)
AC代码为:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 4;
struct node
{
friend bool operator< (node x, node y)
{
if (x.pos == y.pos)return x.r<y.r;
return x.l<y.l;
}
int l, r, id;
int pos;
};
node qu[N];
int n, m, k;
int b[N], num[2 * N];
long long ans[N];
void solve()
{
memset(num, 0, sizeof(num));
int le = 1, ri = 0;
long long temp = 0;
for (int i = 1; i <= m; i++)
{
while (ri<qu[i].r)
{
ri++;
temp += num[b[ri] ^ k];
num[b[ri]]++;
}
while (ri>qu[i].r)
{
num[b[ri]]--;
temp -= num[b[ri] ^ k];
ri--;
}
while (le>qu[i].l - 1)
{
le--;
temp += num[b[le] ^ k];
num[b[le]]++;
}
while (le<qu[i].l - 1)
{
num[b[le]]--;
temp -= num[b[le] ^ k];
le++;
}
ans[qu[i].id] = temp;
}
}
int main()
{
b[0] = 0;
scanf("%d%d%d", &n, &m, &k);
for (int i = 1; i <= n; i++)
{
scanf("%d", &b[i]);
b[i] ^= b[i - 1];
}
int s = sqrt(n);
for (int i = 1; i <= m; i++)
{
scanf("%d%d", &qu[i].l, &qu[i].r);
qu[i].id = i;
qu[i].pos = qu[i].l / s;
}
sort(qu + 1, qu + m + 1);
solve();
for (int i = 1; i <= m; i++)
{
cout << ans[i] << "\n";
}
return 0;
}
CoderForces-617B的更多相关文章
- coderforces #387 Servers(模拟)
Servers time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...
- coderforces #384 D Chloe and pleasant prizes(DP)
Chloe and pleasant prizes time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- coderforces 731c
题目大意:给出m组数据,每组数据包括两个数Li与Ri,分别表示左右袜子的索引(下标),表示这一天要穿的袜子:而我们要使得每天穿的这两只袜子的颜色相同,所以可以改变袜子的颜色,每次只能改变一只袜子的颜色 ...
- coderforces 721b
题目描述: B. Passwords time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- CoderForces 280B(记忆化搜索)
题目大意:一个纸牌游戏,52张纸牌排成一列,每张纸牌有面值和花色两种属性.每次操作可以用最后一张纸牌将倒数第二张或者倒数第四张替换,但前提是两张牌的花色或者面值相同.问最终能否只剩一张牌. 题目分析: ...
- codeforces 617B Chocolate
题意: 在给定01串中,问能分割成多少个子串?每个子串只有一个1. dp #include<iostream> #include<string> #include<alg ...
- Codeforces 617B:Chocolate(思维)
题目链接http://codeforces.com/problemset/problem/617/B 题意 有一个数组,数组中的元素均为0或1 .要求将这个数组分成一些区间,每个区间中的1的个数均为1 ...
- CoderForces 689A Mike and Cellphone (水题)
题意:给定一个手机键盘数字九宫格,然后让你判断某种操作是不是唯一的,也就是说是不是可以通过平移也能实现. 析:我的想法是那就平移一下,看看能实现,就四种平移,上,下,左,右,上是-3,要注意0变成8, ...
- CoderForces 518C Anya and Smartphone (模拟)
题意:给定一个手机,然后一共有 n 个app,告诉你每个屏幕最多放 k 个,现在要你运行 m 个app,每次都从第一个屏幕开始滑动,每运行一个,它就和前一个交换位置,第一个就不换了,现在问你要滑动多少 ...
- CoderForces 518D Ilya and Escalator (期望DP)
题意:给定 n 个人,在每一时刻一个人进入地铁的概率是 p,站着不动的概率是 1-p,然后问你 t 时间地铁里有多少人. 析:很明显这是一个期望DP,用d[i][j]表示 i 时刻 j 个人进入地铁的 ...
随机推荐
- Keras 中间层可视化,附代码详解,以Mnist数字为对象
最近搭建了个Resnet50 的神经网络模型,相看一看中间某一层的输出结果,想感性的感受下逐层提取特征的过程,以数字0为对象,对数字0逐层提取特征,话不多说直接上代码,关于如何搭建Resnet,可以参 ...
- Windows键盘无法调起
Windows 键盘无法调起 经常使用触摸屏幕的小伙伴肯定都遇到过屏幕键盘怎么也唤不起来(在桌面模式下,非平板模式).以下收集了一些常见的解决方案: 注:本文基于 Windows 10 v1903,其 ...
- MyBatis动态语句if与choose的区别
if(通过“title”和“author”两个参数进行可选搜索): <select id="findActiveBlogLike" resultType="Blog ...
- PHP实现微信企业付款到个人零钱步骤
微信支付企业付款到零钱功能应用广泛,比如微信红包奖励,业务结算等.通过企业向个人付款,付款资金将直接进入用户微信零钱. 一 开通条件 付款资金 企业付款到零钱资金使用商户号余额资金. 根据商户号的 ...
- vue项目iframe的传值问题
前言 项目需要,我需要引入一个已经封装好的浏览器插件.插件只能以html的方式调用, 所以.我把插件的使用封装了一个html页面.vue项目则利用iframe的方式引入. 到这里我就遇到了一个问题,那 ...
- Mac上sonar插件的安装及使用
本文主要讲解sonar的安装及使用. 分为两个维度来讲解 1. 使用sonarqube以及自带的Derby数据库 2. 使用sonarqube以及配置mysql数据库 ---------------- ...
- 微擎 manifest.xml
微擎 manifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns= ...
- Qt Framework 问题之 framework/Versions/A:bundle format unrecognized, invalid, or unsuitable
在解决标题提到的问题之后,先来介绍下Qt Framework一些基本知识. 基于QT的Mac端工程,在打包时需要对所有需要嵌入到APP的framework及dylib文件进行手动签名处理. 一.签名处 ...
- 获取单列集合,双列集合,数组的Stream流对象以及简单操作
获取流对象 获取单列集合,双列集合,数组的流对象 单列集合获取流对象: 1.java.util.Collection接口中加入了default方法stream()获取流对象,因此其所有实现类均可通过此 ...
- mac中安装Jenkins+jdk
Jenkins是基于Java开发的一种持续集成工具,用于持续的软件版本发布/测试项目,并监控外部调用执行的工作.简单来说就是自动化测试+部署. 首先我们需要安装jdk,注意,目前jenkins只支持j ...