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 题意翻译 给出一 ...
随机推荐
- 单指令多数据流Single Instruction Multiple Data
Single Instruction Multiple Data,单指令多数据流)能够复制多个操作数,并把它们打包在大型寄存器的一组指令集,例:3DNow!.SSE. SIMD在性能上的优势: 以加法 ...
- Vue实战指南之依赖注入(provide / inject)
案例 UI美眉说咱家的选项菜单太丑了,小哥哥能不能美化一下呀,洒家自然是说小意思啦~自定义一个select组件,so easy~ 简单粗暴型: <el-select v-model=" ...
- 升级python到最新2.7.13
python2.7是2.X的最后一个版本,同时也加入了一部分3.X的新特性.并且具有更好的性能,修改多个bug.所以决定升级到最新的2.7版,我的目前的版本是2.6.6 查看当前python版本 # ...
- requirejs测试
参考资料:http://www.ruanyifeng.com/blog/2012/11/require_js.html 一.文件目录 二.html <!DOCTYPE html> < ...
- hihocoder #1122 二分图二•二分图最大匹配之匈牙利算法(*【模板】应用 )
梳理整个算法: 1. 依次枚举每一个点i: 2. 若点i尚未匹配,则以此点为起点查询一次交错路径. 最后即可得到最大匹配数. 在这个基础上仍然有两个可以优化的地方: 1.对于点的枚举:当我们枚举了所有 ...
- Myeclipse+TestNG白盒测试环境搭建
myeclipse基础环境搭建这里不讲了,我用的是myeclipse2013,网上有破解方法http://jingyan.baidu.com/article/aa6a2c14d0c9700d4c19c ...
- ubuntu的ufw如何开放特定端口?
ubuntu的ufw如何开放特定端口? 1.安装 sudo apt-get install ufw 2.开启 sudo ufw enable 默认关闭外部访问 sudo ufw default den ...
- codeforces 31C Schedule 解题报告
题目链接:http://codeforces.com/problemset/problem/31/C 题目意思:给出 n 个 lessons 你,每个lesson 有对应的 起始和结束时间.问通过删除 ...
- html5--5-6 绘制圆/弧
html5--5-6 绘制圆/弧 学习要点 掌握arc() 方法创建圆弧/曲线(用于创建圆或部分圆) 矩形的绘制方法 rect(x,y,w,h)创建一个矩形 strokeRect(x,y,w,hx,y ...
- HihoCoder 1504 : 骑士游历 (矩阵乘法)
描述 在8x8的国际象棋棋盘上给定一只骑士(俗称“马”)棋子的位置(R, C),小Hi想知道从(R, C)开始移动N步一共有多少种不同的走法. 输入 第一行包含三个整数,N,R和C. 对于40%的数据 ...