BZOJ_5301_[Cqoi2018]异或序列&&CF617E_莫队
Description
Input
Output
Sample Input
1 2 3 1
1 4
1 3
2 3
2 4
4 4
Sample Output
2
1
2
1
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
#define N 100050
typedef long long ll;
ll ans[N],now;
int n,a[N],m,k,h[2000050],pos[N],s[N],size,block,L[N],R[N];
struct A {
int id,l,r;
}q[N];
bool cmp(const A &x,const A &y) {
if(pos[x.l]==pos[y.l]) return x.r<y.r;
return pos[x.l]<pos[y.l];
}
void del(int x) {
h[x]--;
now-=h[x^k];
}
void add(int x) {
now+=h[x^k];
h[x]++;
}
void solve() {
int l=0,r=-1,i;
for(i=1;i<=m;i++) {
while(l<q[i].l) del(s[l]),l++;
while(r>q[i].r) del(s[r]),r--;
while(l>q[i].l) l--,add(s[l]);
while(r<q[i].r) r++,add(s[r]);
ans[q[i].id]=now;
}
}
int main() {
scanf("%d%d%d",&n,&m,&k);
int i,j;
size=sqrt(n); block=n/size;
pos[0]=1;
for(i=1;i<=block;i++) {
L[i]=R[i-1]+1; R[i]=size*i;
for(j=L[i];j<=R[i];j++) {
pos[j]=i;
}
}
if(R[block]!=n) {
block++; for(i=R[block-1];i<=n;i++) pos[i]=block;
}
for(i=1;i<=n;i++) scanf("%d",&a[i]),s[i]=s[i-1]^a[i];
for(i=1;i<=m;i++) {
scanf("%d%d",&q[i].l,&q[i].r); q[i].l--;
q[i].id=i;
}
sort(q+1,q+m+1,cmp);
solve();
for(i=1;i<=m;i++) printf("%lld\n",ans[i]);
}
/*
50 2 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
17 35
3 35
*/
BZOJ_5301_[Cqoi2018]异或序列&&CF617E_莫队的更多相关文章
- BZOJ5301: [Cqoi2018]异或序列(莫队)
5301: [Cqoi2018]异或序列 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 400 Solved: 291[Submit][Status ...
- [bzoj5301][Cqoi2018]异或序列_莫队
异或序列 bzoj-5301 Cqoi-2018 题目大意:题目链接. 注释:略. 想法: 由于a^a=0这个性质,我们将所有的数变成异或前缀和. 所求就变成了求所有的$l_i\le x<y\l ...
- 洛谷P4462 [CQOI2018]异或序列(莫队)
打广告->[这里](https://www.cnblogs.com/bztMinamoto/p/9538115.html) 我蠢了…… 如果$a_{l} xor ...a_{r}=k$,那么只要 ...
- BZOJ5301 [Cqoi2018]异或序列 【莫队】
题目链接 BZOJ5301 题解 莫队水题 BZOJ400AC纪念 #include<algorithm> #include<iostream> #include<cst ...
- 【BZOJ5301】【CQOI2018】异或序列(莫队)
[BZOJ5301][CQOI2018]异或序列(莫队) 题面 BZOJ 洛谷 Description 已知一个长度为 n 的整数数列 a[1],a[2],-,a[n] ,给定查询参数 l.r ,问在 ...
- 【Luogu】P4462异或序列(莫队)
题目链接 观察什么时候x到y之间那一段可以被统计 xorsum[x-1]^xorsum[y]=k xorsum[x-1]=xorsum[y]^k||xorsum[y]=xorsum[x-1]^k 莫队 ...
- bzoj 5301 [Cqoi2018]异或序列 莫队
5301: [Cqoi2018]异或序列 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 204 Solved: 155[Submit][Status ...
- bzoj 5301: [Cqoi2018]异或序列 (莫队算法)
链接:https://www.lydsy.com/JudgeOnline/problem.php?id=5301 题面; 5301: [Cqoi2018]异或序列 Time Limit: 10 Sec ...
- 「luogu4462」[CQOI2018] 异或序列
「luogu4462」[CQOI2018]异或序列 一句话题意 输入 \(n\) 个数,给定\(k\),共 \(m\) 组询问,输出第 \(i\) 组询问 \(l_i\) \(r_i\) 中有多少个连 ...
随机推荐
- Mac环境svn的使用
在Windows环境中,我们一般使用TortoiseSVN来搭建svn环境.在Mac环境下,由于Mac自带了svn的服务器端和客户端功能,所以我们可以在不装任何第三方软件的前提下使用svn功能,不过还 ...
- C#解析json的几种方式
json格式的数据是javascript原生的一种数据格式,比xml更简洁. 它有两种形式:json对象和json对象数组. 在此之前,有必要解释几个基本概念: json字符串,就是string,它一 ...
- C++中,用类和重载运算符写高精模板
先放代码: #include<iostream> #include<cstdio> #include<cstring> using namespace std; s ...
- Spring JTA multiple resource transactions in Tomcat with Atomikos example
http://www.byteslounge.com/tutorials/spring-jta-multiple-resource-transactions-in-tomcat-with-atomik ...
- scrapy安装过程问题解决、新建项目、调试断点
一.安装问题 1. 下载速度太慢 使用国外源,下载速度很慢,可以考虑使用豆瓣的镜像下载 pip install -i https://pypi.douban.com/simple/ scrapy 2. ...
- 条件随机场CRF(二) 前向后向算法评估标记序列概率
条件随机场CRF(一)从随机场到线性链条件随机场 条件随机场CRF(二) 前向后向算法评估标记序列概率 条件随机场CRF(三) 模型学习与维特比算法解码 在条件随机场CRF(一)中我们总结了CRF的模 ...
- 关于ajax原理阐述
ajax是什么呢?说白了就是一个请求,一个读取服务器资源以及提交资源到服务器的中间处理机制,那它具体是怎样工作的,又有怎样的原理呢?var ajax=function(url,fnSucceed,fn ...
- Python_os、os.path、os.shutil使用案例
import os import os.path print(os.path.basename('/Users/c2apple/Desktop/彩屏')) #获取路径的最后一个组成部分 os.path ...
- Python_正则表达式一
''' 常用的正则表达式元字符 . 匹配换行符以外的任意单个字符 * 匹配位于'*'之前的字符或子模的0次或多次出现 + 匹配位于'+'之前的字符或子模式的1次或多次出现 - 用在[]之内用来表示范围 ...
- CAS与OAuth2的区别
CAS与OAuth2的区别 一. CAS的单点登录时保障客户端的用户资源的安全 . OAuth2则是保障服务端的用户资源的安全 . 二. CAS客户端要获取的最终信息是,这个用户到底有没有权限访问我( ...