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\) 中有多少个连 ...
随机推荐
- nginx日志中添加请求的response日志
换个新公司,做一些新鲜的事情,经过一天的琢磨,终于成功添加response日志 在nginx的日志中添加接口response的日志 由于此功能在nginx内置的功能中没有,需要安装第三方模块ngx_l ...
- datagrid 新增,并行内编辑,提交保存
<a class="mini-button" iconCls="icon-add" onclick="addRow()" plain= ...
- miniUI中弹出框问题
---恢复内容开始--- 设置页面弹出框并提交弹出框内容 弹出按钮 <a class="btn_color_1" onclick="onEdit(0)"& ...
- Webapck项目开发基本构建及配置
1.创建项目文件夹 myapp 手动创建myapp,或mkdir myapp 2.cd myapp 3.npm init (初始化项目) 4.一路回车(关于项目信息的填写,可以不写,一路回车即可) 可 ...
- 关于非现场审计软件的一些介绍(ACL、IEDA、Teammate)
http://group.vsharing.com/Article.aspx?aid=661512 IDEA是由caseware开发的数据分析软件.caseware的网址如下:http://www.c ...
- 记住这个网站:服务器相关数据统计网站 http://news.netcraft.com/
http://news.netcraft.com/ 需要参考现在服务器相关数据,可以上这个网站. 当然google趋势也是一个可选得备案. 有一个数据统计更全面的: http://w3techs.co ...
- VueJs(9)---vue-router(进阶1)
vue-router 本文是基于官网学习,官网具体学习目录:vue-router 一.安装 基于vue-cli脚手架安装还是蛮简单的:在文件当前目录下运行: npm install vue-route ...
- Mybatis批量更新数据库与批量插入数据库(以oracle为例)
一.批量更新 1.普通写法(一条记录update一次,性能比较差,容易造成阻塞.不建议使用) <update id="updateBatch" parameterType=& ...
- 在Web中获取MAC地址
很多时候都很难琢磨客户在想什么,也许是自己业务经验不足,也许是客户要显示出他在软件方面也非常的专业.记得以前听过一个故事,说一个富人想娶个媳妇,然后他比较钟意的有三个女人,然后就想从三个女人中选一个, ...
- ectouch 概述
模块(The Model): 即M 主要包含那些用来操作数据库的函数 文件后缀一般是***Model.class.php 路径一般是../mobile/include/apps/default/mod ...