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. 题解:第一道 ...
随机推荐
- Linux下启动/关闭Oracle
一.Linux下启动Oracle Linux下启动Oracle分为两步: 1)启动监听: 2)启动数据库实例: 1.登录服务器,切换到oracle用户,或者以oracle用户登录 [admin@dat ...
- Dockers 部署 MongoDB + mongo-express
1. 拉取 Mongo 镜像 docker pull mongo: 2. 运行镜像 docker run -d --name mongodb --volume /usr/local/mongodat ...
- Brokers类型配置
模块 配置项 作用域 备注 DynamicConnectionQuota max.connectionsmax.connections.per.ipmax.connections.per.ip.ove ...
- tmobst2an
(单选题)与下面代码效果相同的HQL 语句是( ). Criteria criteria = session.createCriteria(User.class); criteria.add(Rest ...
- [git]git入门
usage: git [--version] [--help] [-C <path>] [-c name=value] [--exec-path[=<path>]] [--ht ...
- Altium Designer打印多块PCB到热转印纸上、拼板发给工厂
接下来介绍的方法的优势有: 节省电脑性能(来自不同PCB文件的图案被放置时只在第1块会卡顿一小会儿,之后不再卡顿) 便于排版(拖放图案时绝不会改变图案内容,拖放图案时鼠标拖住的矩形框的尺寸与图案的尺寸 ...
- Spark Streaming运行流程及源码解析(一)
本系列主要描述Spark Streaming的运行流程,然后对每个流程的源码分别进行解析 之前总听同事说Spark源码有多么棒,咱也不知道,就是疯狂点头.今天也来撸一下Spark源码. 对Spark的 ...
- 基于 Serverless Component 全栈解决方案
什么是 Serverless Component Serverless Component 是 Serverless Framework 的,支持多个云资源编排和组织的场景化解决方案. Serverl ...
- 一个工程中cpp文件的编译顺序
做了一个实验. 最后build失败,失败的原因是变量i被重定义了.原本按照我的思路,是不应该失败的.因为我用了条件编译,若先编译Source.cpp,则会#define __HEADER_H__并且定 ...
- MySQL :LAST_INSERT_ID()函数总结
作用:当对table进行insert操作时,返回具有Auto_increment(自动增长)特性的属性列的最新值. 该函数的特点 1.每当断开本次连接之后又重新连接时,该函数的返回值会被重置为0. 2 ...