bzoj 5301: [Cqoi2018]异或序列 (莫队算法)
链接:https://www.lydsy.com/JudgeOnline/problem.php?id=5301
题面;
5301: [Cqoi2018]异或序列
Time Limit: 10 Sec Memory Limit: 512 MB
Submit: 476 Solved: 358
[Submit][Status][Discuss]
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<bits/stdc++.h>
using namespace std;
const int M = 1e5+;
int num[M],a[M],blo,k,ans,b[M];
struct node{
int l,r,id;
bool operator < (const node &cmp)const {
if(l/blo == cmp.l/blo) return r < cmp.r;
return l/blo < cmp.l/blo;
}
}q[M]; void add(int x){
ans += num[k^a[x]];
num[a[x]]++;
} void del(int x){
ans -= num[k^a[x]];
num[a[x]]--;
} int main()
{
int n,m;
cin>>n>>m>>k;
blo = sqrt(n);
for(int i = ;i <= n;i ++){
cin>>a[i];
a[i] = a[i]^a[i-];
}
for(int i = ;i <= m;i ++){
cin>>q[i].l>>q[i].r;
q[i].l --;
q[i].id = i;
}
sort(q+,q+m+);
int l = ,r = ;
ans = ;
for(int i = ;i <= m;i ++){
while(l < q[i].l) del(l),l++;
while(l > q[i].l) l--,add(l);
while(r < q[i].r) r++,add(r);
while(r > q[i].r) del(r),r--;
b[q[i].id] = ans;
}
for(int i = ;i <= m;i ++){
cout<<b[i]<<endl;
} }
bzoj 5301: [Cqoi2018]异或序列 (莫队算法)的更多相关文章
- bzoj 5301 [Cqoi2018]异或序列 莫队
5301: [Cqoi2018]异或序列 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 204 Solved: 155[Submit][Status ...
- BZOJ5301:[CQOI2018]异或序列(莫队)
Description 已知一个长度为 n 的整数数列 a[1],a[2],…,a[n] ,给定查询参数 l.r ,问在 [l,r] 区间内,有多少连续子 序列满足异或和等于 k . 也就是说,对于所 ...
- 洛谷P4462 [CQOI2018]异或序列(莫队)
题意 题目链接 Sol 一开始以为K每次都是给出的想了半天不会做. 然而发现读错题了维护个前缀异或和然后直接莫队搞就行,. #include<bits/stdc++.h> #define ...
- bzoj 5301: [Cqoi2018]异或序列
蛤?这一年cqoi的题这么水???? 这不就是个sb莫队吗 这样写怕是会被打死,,, 注意\(a_x\ XOR a_{x+1}\ XOR\ ...\ a_{y}=s_{x-1}\ XOR\ s_y\) ...
- [CQOI2018]异或序列 (莫队,异或前缀和)
题目链接 Solution 有点巧的莫队. 考虑到区间 \([L,R]\) 的异或和也即 \(sum[L-1]~\bigoplus~sum[R]\) ,此处\(sum\)即为异或前缀和. 然后如何考虑 ...
- P4462 [CQOI2018]异或序列 莫队
题意:给定数列 \(a\) 和 \(k\) ,询问区间 \([l,r]\) 中有多少子区间满足异或和为 \(k\). 莫队.我们可以记录前缀异或值 \(a_i\),修改时,贡献为 \(c[a_i\bi ...
- CQOI2018异或序列 [莫队]
莫队板子 用于复习 #include <cstdio> #include <cstdlib> #include <algorithm> #include <c ...
- luogu P4462 [CQOI2018]异或序列 |莫队
题目描述 已知一个长度为n的整数数列a1,a2,...,an,给定查询参数l.r,问在al,al+1,...,ar区间内,有多少子序列满足异或和等于k.也就是说,对于所有的x,y (I ≤ x ≤ ...
- BZOJ 3809 Gty的二逼妹子序列 莫队算法+分块
Description Autumn和Bakser又在研究Gty的妹子序列了!但他们遇到了一个难题. 对于一段妹子们,他们想让你帮忙求出这之内美丽度∈[a,b]的妹子的美丽度的种类数. 为了方便,我们 ...
随机推荐
- jquery中的$.fn的用法
JQuery里的原型prototype分析 http://www.nowamagic.net/librarys/veda/detail/653 jquery中的$.fn的用法 ...
- 从零开始学安全(四十)●上传文件MIME类型绕过漏洞防御
MIME检测原理 服务端MIME类型检测是通过检查http包的Content-Type字段中的值来判断上传文件是否合法的. php示例代码: if($_FILES['userfile']['type' ...
- idea git提交时候提示 --author 'java_suisui' is not 'Name ' and matches no existing author
今天使用idea修改git项目的作者信息,提交时遇到错误: 0 files committed, 1 file failed to commit: test --author 'java_suisui ...
- mybatis 参数格式异常-- Error querying database. Cause: java.lang.NumberFormatException: For input string
mybatis中 <if></if>标签中进行判断时,如果传入的时字符格式和数字进行判断需要将数字进行转译,否则默认是数字和数字进行比较,这是就会出现参数格式异常如<if ...
- 个人博客制作如何选择前端模板 thinkcmf后台加载新模板 CSS js文件
我们的博客后台已经搭建好了,接下来我就要选择一个合适的模板做自己的博客,首先要定位你的博客是做什么用的,是属于什么行业,根据自己博客的定位选择适合的模板. 如果你是设计师,又会前端设计开发,那就可以自 ...
- django apscheduler在特定时间执行一次任务(run at a specify time only once)
如何使程序在特定时间只执行一次,我查了一下. celery可以,时间以秒计. task = mytask.apply_async(args=[10, 20], countdown=60) 不过,我 ...
- Windows中通过命令行启动打开Service 管理工具
经常需要打开Services 管理工具操控Service 的启动,停止. 通过控制面板 --> 管理工具 -->Service 太慢. 学到一个快捷方式. windows + R 启动 ...
- 记录未预编译文件“*.aspx”,因此不能请求该文件的几种处理办法
对应Framework版本重新注册 2.0:C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -i 4.0:C:\Wind ...
- 搭建Hadoop的环境
准备实验的环境: 1.安装Linux.JDK 2.配置主机名.免密码登录 3.约定:安装目录:/usr/local/bin 安装: 1.解压 : tar -zxvf hadoop-2.7.7.tar. ...
- @EnableFeignClients 注解
feignClents在spring容器里找不到的原因 当使用的feignClents 来自引用别的工程时,需要指定包名,如果不指定就算使用ComponentScan 扫描也不行 import org ...