E. XOR and Favorite Number (莫队板子题)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
} /********************************************************************/ const int maxn = 1e5+;
int n, m, k;
int a[maxn], belong[maxn];
ll ans[maxn], flag[maxn*]; //注意这里的flag 要大大大大
ll now; struct node{
int l, r;
int id;
}q[maxn]; bool cmp(node x, node y){
if(belong[x.l] == belong[y.l])
return x.r < y.r;
return belong[x.l] < belong[y.l];
} void Update(int x){
now += flag[a[x]^k];
flag[a[x]]++;
} void Delete(int x){
flag[a[x]]--;
now -= flag[a[x]^k];
} int main(){
n = read(); m = read(); k = read();
int sz = ceil(sqrt(n));
for(int i = ;i <= n;i++){
a[i] = read();
belong[i] = (i-)/sz;
}
//前缀异或
for(int i = ;i <= n;i++){
a[i] = a[i-]^a[i];
}
for(int i = ;i <= m;i++){
q[i].l = read(); q[i].r = read();
q[i].id = i;
}
sort(q+, q++m, cmp);
int l = , r = ;
now = ;
flag[] = ;
for(int i = ;i <= m;i++){
int id = q[i].id; //while里面的顺序是不能随意更改的
while(l < q[i].l){
Delete(l-);
l++;
}
while(l > q[i].l){
l--;
Update(l-);
}
while(r < q[i].r){
r++;
Update(r);
}
while(r > q[i].r){
Delete(r);
r--;
}
ans[id] = now;
}
for(int i = ;i <= m;i++){
cout << ans[i] << endl;
}
return ;
}
E. XOR and Favorite Number (莫队板子题)的更多相关文章
- 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 Round #340 (Div. 2) E XOR and Favorite Number 莫队板子
#include<bits/stdc++.h> using namespace std; <<; struct node{ int l,r; int id; }q[N]; in ...
- Codeforces617 E . XOR and Favorite Number(莫队算法)
XOR and Favorite Number time limit per test: 4 seconds memory limit per test: 256 megabytes input: s ...
- 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 617E E. XOR and Favorite Number(莫队算法)
题目链接: E. XOR and Favorite Number time limit per test 4 seconds memory limit per test 256 megabytes i ...
- 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 - 617E XOR and Favorite Number 莫队算法
https://vjudge.net/problem/CodeForces-617E 题意,给你n个数ax,m个询问Ly,Ry, 问LR内有几对i,j,使得ai^...^ aj =k. 题解:第一道 ...
- Codeforces 617E XOR and Favorite Number莫队
http://codeforces.com/contest/617/problem/E 题意:给出q个查询,每次询问区间内连续异或值为k的有几种情况. 思路:没有区间修改,而且扩展端点,减小端点在前缀 ...
- E. XOR and Favorite Number 莫队 2038: [2009国家集训队]小Z的袜子(hose)
一直都说学莫队,直到现在才学,训练的时候就跪了 T_T,其实挺简单的感觉.其实训练的时候也看懂了,一知半解,就想着先敲.(其实这样是不好的,应该弄懂再敲,以后要养成这个习惯) 前缀异或也很快想出来 ...
- SP3267 DQUERY - D-query 莫队板子题
题意可见:https://www.luogu.com.cn/problem/SP3267 可在vj上提交:https://vjudge.net/problem/SPOJ-DQUERY 题意翻译 给出一 ...
随机推荐
- 云计算系列——HIVE1.2.1 - JDBC 服务
前提 Hadoop 集群已经启动 Hive1.2.1 环境已经搭建 一.启动 HIVE - JDBC 服务 hiveserver2 为 hive 的 jdbc 服务,此服务默认为前台进程,需要在执行 ...
- machine learning for hacker记录(1) R与机器学习
开篇:首先这本书的名字很霸气,全书内容讲的是R语言在机器学习上面的应用,一些基本的分类算法(tree,SVM,NB),回归算法,智能优化算法,维度约减等,机器学习领域已经有很多成熟的R工具箱,毕竟这个 ...
- java基础以及操作Excle
今天把会经常用的几个集合的迭代方法又练习了一下,放在这里,经常复习! map集合迭代 /*** 迭代map[1]*/ for (Integer key : map.keySet()) {//迭代key ...
- FFmpeg big changes. ffmpeg 接口的一些改变
Big changes have been made from FFmpeg 0.5.1… Refer to http://cekirdek.pardus.org.tr/~ismail/ffmpeg- ...
- svg矢量图制作工具(Sketsa SVG Editor) v7.1.1 中文免费版
下载地址:https://www.jb51.net/softs/555253.html Sketsa SVG Editor中文版是一款强大好用的矢量图绘制工具,该工具的最大特色就是集成了中文语言,且支 ...
- linux下syslog使用说明
转自:http://blog.chinaunix.net/uid-25120309-id-3359929.html syslog 系统日志应用 1) 概述 syslog是Linux系统默 ...
- 如何使用 Jmeter 发送 Json 请求
公司最近有一个项目,需要持续发送大量的 Json 请求到服务器,从而测试服务器可靠性. 我就发送 Json 请求部分发布这个博客. 一般来说, Json 请求的数据都保存到 CSV 文件中,然后使用 ...
- JS-React:React.js
ylbtech-JS-React:React.js react (软件行业名词) React 起源于 Facebook 的内部项目,因为该公司对市场上所有 JavaScript MVC 框架,都不满意 ...
- node process-进程
process对象是一个全局变量,提供Node.js进程的有关信息以及控制进程.因为是全局变量所以可以直接使用
- keil5中文乱码的解决
keil5 复制出来的中文显示乱码,该如何解决? 点击Edit - Configuration ,进入编辑器设置: 点击ok ,就可以了