BZOJ5301 [Cqoi2018]异或序列 【莫队】
题目链接
题解
莫队水题
BZOJ400AC纪念
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<map>
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define mp(a,b) make_pair<int,int>(a,b)
#define cls(s) memset(s,0,sizeof(s))
#define cp pair<int,int>
#define LL long long int
using namespace std;
const int maxn = 100005,maxm = 100005,INF = 1000000000;
inline int read(){
int out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();}
while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}
return out * flag;
}
int bac[maxn],a[maxn],n,m,K,B;
LL ans[maxn];
struct Que{int l,r,b,id;}q[maxn];
inline bool operator <(const Que& a,const Que& b){
return a.b == b.b ? a.r < b.r : a.l < b.l;
}
void solve(){
sort(q + 1,q + 1 + m);
int L = q[1].l,R = q[1].r,tmp; LL cnt = 0;
for (int i = q[1].l; i <= q[1].r; i++){
tmp = a[i] ^ K;
cnt += bac[tmp];
bac[a[i]]++;
}
ans[q[1].id] = cnt;
for (int i = 2; i <= m; i++){
while (L != q[i].l || R != q[i].r){
if (L > q[i].l){
L--;
tmp = a[L] ^ K;
cnt += bac[tmp];
bac[a[L]]++;
}
if (L < q[i].l){
tmp = a[L] ^ K;
bac[a[L]]--;
cnt -= bac[tmp];
L++;
}
if (R < q[i].r){
R++;
tmp = a[R] ^ K;
cnt += bac[tmp];
bac[a[R]]++;
}
if (R > q[i].r){
tmp = a[R] ^ K;
bac[a[R]]--;
cnt -= bac[tmp];
R--;
}
}
ans[q[i].id] = cnt;
}
REP(i,m) printf("%lld\n",ans[i]);
}
int main(){
n = read(); m = read(); K = read(); B = (int)sqrt(n) + 1;
REP(i,n) a[i] = a[i - 1] ^ read();
REP(i,m) q[i].id = i,q[i].l = read() - 1,q[i].r = read(),q[i].b = q[i].l / B;
solve();
return 0;
}
BZOJ5301 [Cqoi2018]异或序列 【莫队】的更多相关文章
- BZOJ5301:[CQOI2018]异或序列(莫队)
Description 已知一个长度为 n 的整数数列 a[1],a[2],…,a[n] ,给定查询参数 l.r ,问在 [l,r] 区间内,有多少连续子 序列满足异或和等于 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 ...
- 洛谷P4462 [CQOI2018]异或序列(莫队)
题意 题目链接 Sol 一开始以为K每次都是给出的想了半天不会做. 然而发现读错题了维护个前缀异或和然后直接莫队搞就行,. #include<bits/stdc++.h> #define ...
- [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 ≤ ...
- 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 ...
随机推荐
- REST Adapter实现SAP PI中的增强XML/JSON格式转换(转载)
SAP标准的REST adapter有着XML/JSON转换的功能,它很有用,因为一方面SAP PI/PO内部以XML格式处理数据,而另一方面,在处理REST架构风格的时候,JSON才是事实上的格式. ...
- Linux基础知识随笔记
linux文件属性 ls -h human-readable以人类可读的形式显示 -i 显示inode号码 [root@oldboyedu55-bjb ~]# ls -ihl total 8.0K 3 ...
- scrapy--BeautifulSoup
BeautifulSoup官方文档:https://beautifulsoup.readthedocs.io/zh_CN/latest/#id8 太繁琐的,精简了一些自己用的到的. 1.index.h ...
- 虚拟机无法ping通物理机的解决方案
环境:Windows7下安装虚拟机,虚拟机上装有Ubuntu16.04的server版系统. 1.打开Windows防火墙,在打开或关闭Windows防火墙中 关闭Windows的防火墙. 2.禁用服 ...
- Android面试收集录9 IntentService详解
一. 定义 IntentService是Android里面的一个封装类,继承自四大组件之一的Service. 二.作用 处理异步请求,实现多线程 三. 工作流程 注意:若启动IntentService ...
- WPF点击不同界面上的按钮实现界面切换
原文:WPF点击不同界面上的按钮实现界面切换 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/qq_29844879/article/details/ ...
- SpringMVC---applicationContext.xml配置详解
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- sql server inser相关处理(添加一条,一次添加多条,Bulk插入多条)
1,insert语句 insert into 表一(字段一,字段二,字段三) value(值一,值二,值三) 2,sql 插入多条语句,其中完整值之间用逗号分割 insert into 表一(字段一, ...
- django之python3.4及以上连接mysql的一些问题记录
首先,祭出大杀器whl https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient django1.x与django2.x 在项目的写法上有一些区别 ...
- C# p-Inovke C++动态链接库
在C++的动态链接库 写了一个测试方法,然后想在C#客户端进行pInvoke调用,始终报异常如下: 试图加载格式不正确的程序. (异常来自 HRESULT:0x8007000B). 最后发现, 需要将 ...