bzoj 5301 [Cqoi2018]异或序列 莫队
5301: [Cqoi2018]异或序列
Time Limit: 10 Sec Memory Limit: 512 MB
Submit: 204 Solved: 155
[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<cstring>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<iostream> #define N 100007
#define ll long long #define Wb putchar(' ')
#define We putchar('\n')
#define rg register int
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-;ch=getchar();}
while(isdigit(ch)){x=(x<<)+(x<<)+ch-'';ch=getchar();}
return x*f;
}
inline void write(ll x)
{
if(x<) putchar('-'),x=-x;
if (x==) putchar();
int num=;char c[];
while(x) c[++num]=(x%)+,x/=;
while(num) putchar(c[num--]);
} int n,m,K,blo;
int a[N],bel[N],cnt[N<<];
ll ans[N];
struct Node
{
int l,r,id;
friend bool operator<(Node x,Node y)
{
if (bel[x.l]!=bel[y.l]) return bel[x.l]<bel[y.l];
return x.r<y.r;
}
}Q[N]; void solve()
{
int l=,r=;ll res=;
for (int i=;i<=m;i++)
{
while(l<Q[i].l-)
cnt[a[l]]--,res-=cnt[K^a[l]],l++;
while(l>Q[i].l-)
l--,res+=cnt[K^a[l]],cnt[a[l]]++;
while(r<Q[i].r)
r++,res+=cnt[K^a[r]],cnt[a[r]]++;
while(r>Q[i].r)
cnt[a[r]]--,res-=cnt[K^a[r]],r--;
ans[Q[i].id]=res;
}
}
int main()
{
n=read(),m=read(),K=read(),blo=(int)sqrt(n);
for (rg i=;i<=n;i++) a[i]=read()^a[i-];
for (rg i=;i<=n;i++) bel[i]=(i-)/blo+;
for (rg i=;i<=m;i++)
Q[i].l=read(),Q[i].r=read(),Q[i].id=i;
sort(Q+,Q+m+);
solve();
for (rg i=;i<=m;i++)
write(ans[i]),We;
}
bzoj 5301 [Cqoi2018]异或序列 莫队的更多相关文章
- bzoj 5301: [Cqoi2018]异或序列 (莫队算法)
链接:https://www.lydsy.com/JudgeOnline/problem.php?id=5301 题面; 5301: [Cqoi2018]异或序列 Time Limit: 10 Sec ...
- 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 ≤ ...
- 【CQOI2018】异或序列 - 莫队
题目描述 已知一个长度为n的整数数列 $a_1,a_2,...,a_n$,给定查询参数l.r,问在 $a_l,a_{l+1},...,a_r$ 区间内,有多少子序列满足异或和等于k.也就是说,对于 ...
随机推荐
- Java 的 java_home, path, classpath
java_home: 指定 jdk 的安装目录. 第三方软件 Eclipse / Tomcat 在 java_home 指定的目录下查找安装好的 jdk. path: 配置 jdk 的安装目录.在命令 ...
- (转)一个简单的rest_framework demo
转发:https://www.cnblogs.com/fu-yong/p/9100559.html models.py 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 from ...
- Apache 工作模式的正确配置
prefork work event
- 冲刺One之站立会议4 /2015-5-17
今天我们继续了昨天未完成的部分,把服务器端的在线人数显示做了出来,但是在调试的时候还有一些不可预知的自己也不会改的bug,让我们有点不知所措,启动时间的显示相对来说比较容易实现. 燃尽图4
- 对网络助手的NABCD分析心得
Sunny--Code团队::刘中睿,杜晓松,郑成 我们小组这次做的软件名字叫为校园网络助手.在大学学习的同学都知道学校里面有着内网与外网两种,并且有着流量限制,所以我们设计出来了这项软件,它主要有着 ...
- Leetcode题库——13.罗马数字转整数
@author: ZZQ @software: PyCharm @file: Luoma2Int.py @time: 2018/9/16 17:06 要求: 罗马数字转数字 字符 数值 I 1 V 5 ...
- Current request is not a multipart request
1. 文件上传需要在form表单中添加<form enctype="multipart/form-data"> 2. SpringMVC默认是关闭fileupload功 ...
- MVC框架理解及优缺点
MVC:模型(Model).视图(View).控制器(Control) 流程如下: 首先是视图向控制器发送请求,控制器再将业务请求发送给模型, 然后模型处理请求业务并把结果返回给控制器,控制器根据结果 ...
- LinkedList,HashSet,HashMap
LinkedList底层源码是采用双向链表实现的 private static class Node<E> { E item;//节点值 Node<E> next;//节点后指 ...
- jenkins 通过maven部署Tomcat8报错
问题过程 jenkins执行构建过程中,可以在workspace/项目名/target/目录下产生xxx.jar文件 但是在执行构建后操作时报出如下错误 [INFO] ---------------- ...