[CQOI2018]异或序列
嘟嘟嘟
前缀和+莫队。
先用前缀和预处理异或,于是问题变成了在\([L - 1, R]\)中求两个数异或等于\(k\)的数对个数。
然后就离线排序,按套路维护两个指针加加减减,并维护一个桶,每一次加\(x\),答案就加上\(bac[x ^ k]\),并且++\(bac[x]\),删除就减去贡献。
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define In inline
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
const int maxn = 1e5 + 5;
inline ll read()
{
ll ans = 0;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) last = ch, ch = getchar();
while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < 0) x = -x, putchar('-');
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
}
int n, m, k, S, sum[maxn];
struct Node
{
int L, R, id, b;
In bool operator < (const Node& oth)const
{
return b < oth.b || (b == oth.b && R < oth.R);
}
}q[maxn];
ll cnt = 0, bac[maxn], ans[maxn];
In void add(int x)
{
cnt += bac[x ^ k], ++bac[x];
}
In void del(int x)
{
--bac[x], cnt -= bac[x ^ k];
}
int main()
{
n = read(), m = read(), k = read(); S = sqrt(n);
for(int i = 1; i <= n; ++i) sum[i] = read(), sum[i] ^= sum[i - 1];
for(int i = 1; i <= m; ++i)
{
int L = read() - 1, R = read();
q[i] = (Node){L, R, i, (L - 1) / S + 1};
}
sort(q + 1, q + m + 1);
for(int i = 1, l = 1, r = 0; i <= m; ++i)
{
while(l < q[i].L) del(sum[l++]);
while(l > q[i].L) add(sum[--l]);
while(r < q[i].R) add(sum[++r]);
while(r > q[i].R) del(sum[r--]);
ans[q[i].id] = cnt;
}
for(int i = 1; i <= m; ++i) write(ans[i]), enter;
return 0;
}
[CQOI2018]异或序列的更多相关文章
- 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\) 中有多少个连 ...
- bzoj 5301 [Cqoi2018]异或序列 莫队
5301: [Cqoi2018]异或序列 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 204 Solved: 155[Submit][Status ...
- 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 ...
- BZOJ_5301_[Cqoi2018]异或序列&&CF617E_莫队
Description 已知一个长度为 n 的整数数列 a[1],a[2],…,a[n] ,给定查询参数 l.r ,问在 [l,r] 区间内,有多少连续子 序列满足异或和等于 k . 也就是说,对于所 ...
- bzoj5301[CQOI2018]异或序列
题意 已知一个长度为 n 的整数数列 a[1],a[2],-,a[n] ,给定查询参数 l.r ,问在 [l,r] 区间内,有多少连续子 序列满足异或和等于 k . 也就是说,对于所有的 x,y (l ...
- BZOJ5301:[CQOI2018]异或序列(莫队)
Description 已知一个长度为 n 的整数数列 a[1],a[2],…,a[n] ,给定查询参数 l.r ,问在 [l,r] 区间内,有多少连续子 序列满足异或和等于 k . 也就是说,对于所 ...
- LuoguP4462 [CQOI2018]异或序列
https://zybuluo.com/ysner/note/1124952 题面 给你一个大小为\(n\)的序列,然后给你一个数字\(k\),再给出\(m\)组询问,询问给出一个区间,问这个区间里面 ...
- 并不对劲的复健训练-bzoj5301:loj2534:p4462 [CQOI2018]异或序列
题目大意 给出一个序列\(a_1,...,a_n\)(\(a,n\leq 10^5\)),一个数\(k\)(\(k\leq 10^5\)),\(m\)(\(m\leq10^5\))次询问,每次询问给\ ...
随机推荐
- Object类型转换成自定义类型(向下转型)
Object类型转换成自定义类型 场景: 从数据库或者别的途径接收对象的时候用Object,但是用的时候怎么object点(方法提示 | alt+'/'),都点不出自定义类型的方法. 比如,数据库查询 ...
- Android Lifecycle使用
引言 Lifecycle 是官方提供的架构组件之一,目前已经是稳定版本,Lifecycle 组件包括LifecycleOwner.LifecycleObserver.Lifecycle 组件是执行操作 ...
- Spring之AOP在XML中的配置方法
AOP 即 Aspect Oriental Program 面向切面编程 先来一个栗子: <aop:config> <aop:pointcut id="loggerCutp ...
- [CSS] Transitions动画效果(1)
Transitions动画效果(1) 源码 https://github.com/YouXianMing/CSS-Animations/tree/master/Transitions 效果 细节
- python itchat 爬取微信好友信息
原文链接:https://mp.weixin.qq.com/s/4EXgR4GkriTnAzVxluJxmg 「itchat」一个开源的微信个人接口,今天我们就用itchat爬取微信好友信息,无图言虚 ...
- Android为TV端助力 遥控器的映射
第一编写kl文件时先在盒子上输入getevent -v查看设备信息,设备信息里有vendor.product.version, 假如分别是xxxx,yyyy,zzzz,那么你的文件名就要命名为Vend ...
- ngx-moment汉化
1.导入汉化文件 import '../../../node_modules/moment/locale/zh-cn.js' 2.使用汉化 <span>{{item.time|amLoca ...
- django 与 Vue 的结合使用说明
1.第一步有一个Django项目 先是创建一个Django项目 django-admin startproject demo 然后创建一个application应用 python manage.py ...
- (后端)mybatis中使用Java8的日期LocalDate、LocalDateTime
原文地址:https://blog.csdn.net/weixin_38553453/article/details/75050632 MyBatis的型处理器是属性“createdtime参数映射为 ...
- (后台)SQL Server 代理(已禁用代理 XP) 怎么解决(转)
百度知道搜索的答案: 在SQL Server Management Studio中连接到SQL Server实例后,会显示“SQL Server 代理”节点.如果当前该实例的Agent服务没有启动,“ ...