Codeforces Round #340 (Div. 2) E XOR and Favorite Number 莫队板子
#include<bits/stdc++.h>
using namespace std;
const int N=<<;
struct node{
int l,r;
int id;
}q[N];
int pos[N];
long long ans[N];
//每个前缀值出现的次数
long long flag[N];
int a[N];
bool cmp(node a,node b)
{
//如果左端点在同一块中,按右端点排序
if(pos[a.l]==pos[b.l])
return a.r<b.r;
//否则,按照块来排序
return pos[a.l]<pos[b.l];
}
int n,m,k;
int l=,r=;
long long Ans=;
void add(int x)
{
//当前 前缀和出现的次数--
Ans+=flag[a[x]^k];
flag[a[x]]++;
}
void del(int x)
{
//当前 前缀和出现的次数--
flag[a[x]]--;
//总的减去
Ans-=flag[a[x]^k];
}
int main()
{
cin>>n>>m>>k;
int sz=sqrt(n);
for(int i=;i<=n;i++)
{
cin>>a[i];
//处理前缀和
a[i]=a[i]^a[i-];
//分块
pos[i]=i/sz;
}
for(int i=;i<=m;i++)
{
cin>>q[i].l>>q[i].r;
q[i].id=i;
}
sort(q+,q++m,cmp);
flag[]=;
for(int i=;i<=m;i++)
{
while(l<q[i].l)
{
del(l-);
l++;
}
while(l>q[i].l)
{
l--;
add(l-);
}
while(r<q[i].r)
{
r++;
add(r);
}
while(r>q[i].r)
{
del(r);
r--;
}
ans[q[i].id]=Ans;
}
for(int i=;i<=m;i++)
cout<<ans[i]<<endl;
return ;
}
Codeforces Round #340 (Div. 2) E XOR and Favorite Number 莫队板子的更多相关文章
- Codeforces Round #340 (Div. 2) E. XOR and Favorite Number 莫队算法
E. XOR and Favorite Number 题目连接: http://www.codeforces.com/contest/617/problem/E Descriptionww.co Bo ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- [Codeforces Round #340 (Div. 2)]
[Codeforces Round #340 (Div. 2)] vp了一场cf..(打不了深夜的场啊!!) A.Elephant 水题,直接贪心,能用5步走5步. B.Chocolate 乘法原理计 ...
- Codeforces Round #340 (Div. 2) E 莫队+前缀异或和
E. XOR and Favorite Number time limit per test 4 seconds memory limit per test 256 megabytes input s ...
- CODEFORCES 340 XOR and Favorite Number 莫队模板题
原来我直接学的是假的莫队 原题: Bob has a favorite number k and ai of length n. Now he asks you to answer m queries ...
- CodeForces - 617E XOR and Favorite Number 莫队算法
https://vjudge.net/problem/CodeForces-617E 题意,给你n个数ax,m个询问Ly,Ry, 问LR内有几对i,j,使得ai^...^ aj =k. 题解:第一道 ...
随机推荐
- VirtualBox 虚拟机 从入门到入坑
...
- map实现单词转换程序的例子
代码来源于c++ primer 10.3 功能:已知一个一一对应的词典,求一小段文档对应的“翻译” 词典如下: A a B b C c D d E e 输入: D D E 代码: //需要两个文件,一 ...
- 理解RabbitMQ中的AMQP-0-9-1模型
前提 之前有个打算在学习RabbitMQ之前,把AMQP详细阅读一次,挑出里面的重点内容.后来找了下RabbitMQ的官方文档,发现了有一篇文档专门介绍了RabbitMQ中实现的AMQP模型部分,于是 ...
- uml-类图书写指南
说明 类图是最常用的UML图,面向对象建模的主要组成部分.它用于描述系统的结构化设计,显示出类.接口以及它们之间的静态结构和关系. 类图主要产出于面向对象设计的分析和设计阶段,用来描述系统的静态结构. ...
- 死磕mysql(5)
高性能mysql --查看隐藏的库//use mysql --创建新用户//create user 'new'@'localhost' identified by ''; --创建用户 '用户名'@' ...
- data structure test
1.设计算法,对带头结点的单链表实现就地逆置.并给出单链表的存储结构(数据类型)的定义. #include <iostream> #include <cstdlib> #inc ...
- web开发发展历程
cs架构:(软件主要运行在桌面上,数据库软件运行在服务器端) 缺点:如果web应用修改或升级,需要每个客户端逐个升级桌面App,因此Browser/server模式开始流行. bs架构:应用程序的逻辑 ...
- [python之路]格式化显示
格式化显示 格式规范微语言 中文版 以下整理自 python字符串格式化 *输出结果的空格在md预览中没效果(用代码块三个撇号就可以保留格式了) 一.使用格式化符来格式化字符串: Python支持的所 ...
- 题解 【[MdOI2020] Decrease】
\[ \texttt{Preface} \] 感觉 C 比 B 还简单? \[ \texttt{Description} \] 给定一个 \(n×n\) 的矩阵,你可以进行若干次操作. 每次操作,你可 ...
- 转载 angularJS filter 过滤器
angularjs中的filter(过滤器) 标签: angularjsfilter 源文地址:http://www.ncloud.hk/技术分享/angularjs中的filter-过滤器/ f ...