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 题意翻译 给出一 ...
随机推荐
- Delphi类的默认区域
//类中数据成员的排列顺序一般是: 字段.方法.属性 //访问权限区域的顺序一般是: 无限制区(默认 published) private protected public pub ...
- mongodb学习之:主从复制
在sql server能够做到读写分离,双机热备份和集群部署,这些在mongodb也能做到.首先来看主从复制.我们就在一台电脑上进行操作 第一步:分别建立master和slave两个文件夹 第二步:开 ...
- Android Touch事件分发
跟touch事件相关的3个方法: public boolean dispatchTouchEvent(MotionEvent ev); //用来分派event public boolean onInt ...
- 重新认识vue之事件阻止冒泡
冒泡的表现 近期用vue做了一个需求,大概是同一个区域,点击不同位置有不同的响应函数,还有个总的响应函数,好吧,如下图所示: 他们的DOM结构如下: <div v-for="(item ...
- POJ 2506 Tiling (递推 + 大数加法模拟 )
Tiling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7965 Accepted: 3866 Descriptio ...
- codeforces B. Bear and Strings 解题报告
题目链接:http://codeforces.com/problemset/problem/385/B 题目意思:给定一条只有小写英文组成的序列,需要找出至少包含一个“bear”的单词的子序列个数.注 ...
- the art of seo(chapter seven)
Content Marketing ***Leveraging Major Social Media Platforms***LinkedIn, Facebook,Google+, Pinterest ...
- JavaWeb学习总结(三)response与request
一.response response是Servlet.service方法的一个参数,类型为javax.servlet.http.HttpServletResponse.在客户端发出每个请求时,服务器 ...
- 在Eclipse配置自动提示
1.我们打开eclipse,选择菜单栏的window选项 2.点击Windows,选择下拉菜单里面的preferences选项,之后在打开的对话框的左侧找到Java选项 3.之后点击Java选项,选择 ...
- [APIO 2014] 序列分割
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=3675 [算法] 首先 , 我们发现将一段序列切成若干段所获得的收益与顺序无关 于是我 ...