题意

题目链接

Sol

一开始以为K每次都是给出的想了半天不会做。

然而发现读错题了维护个前缀异或和然后直接莫队搞就行,。

#include<bits/stdc++.h>
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
//#define int long long
#define LL long long
#define Fin(x) {freopen(#x".in","r",stdin);}
#define Fout(x) {freopen(#x".out","w",stdout);}
using namespace std;
const int MAXN = 1e6 + 10, mod = 998244353, INF = 1e9 + 10;
const double eps = 1e-9;
template <typename A, typename B> inline bool chmin(A &a, B b){if(a > b) {a = b; return 1;} return 0;}
template <typename A, typename B> inline bool chmax(A &a, B b){if(a < b) {a = b; return 1;} return 0;}
template <typename A, typename B> inline LL add(A x, B y) {if(x + y < 0) return x + y + mod; return x + y >= mod ? x + y - mod : x + y;}
template <typename A, typename B> inline void add2(A &x, B y) {if(x + y < 0) x = x + y + mod; else x = (x + y >= mod ? x + y - mod : x + y);}
template <typename A, typename B> inline LL mul(A x, B y) {return 1ll * x * y % mod;}
template <typename A, typename B> inline void mul2(A &x, B y) {x = (1ll * x * y % mod + mod) % mod;}
template <typename A> inline void debug(A a){cout << a << '\n';}
template <typename A> inline LL sqr(A x){return 1ll * x * x;}
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N, Q, K, a[MAXN], num[MAXN], belong[MAXN], block;
LL now, ans[MAXN];
struct Query {
int l, r, id;
bool operator < (const Query &rhs) const {
return belong[l] == belong[rhs.l] ? r < rhs.r : belong[l] < belong[rhs.l];
}
}q[MAXN];
void Add(int x) {
now += num[K ^ x];
num[x]++;
}
void Delet(int x) {
num[x]--;
now -= num[K ^ x];
}
void solve() {
int l = 1, r = 0;
for(int i = 1; i <= Q; i++) {
while(r < q[i].r) Add(a[++r]);
while(r > q[i].r) Delet(a[r--]);
while(l < q[i].l) Delet(a[l++]);
while(l > q[i].l) Add(a[--l]);
ans[q[i].id] = now;
}
}
signed main() {
N = read(); Q = read(); K = read(); block = sqrt(N);
for(int i = 1; i <= N; i++) a[i] = read() ^ a[i - 1], belong[i] = (i - 1) / block + 1;
for(int i = 1; i <= Q; i++) q[i].l = read() - 1, q[i].r = read(), q[i].id = i;
sort(q + 1, q + Q + 1);
solve();
for(int i = 1; i <= Q; i++) cout << ans[i] << '\n';
return 0;
}

洛谷P4462 [CQOI2018]异或序列(莫队)的更多相关文章

  1. 洛谷P4462 [CQOI2018]异或序列(莫队)

    打广告->[这里](https://www.cnblogs.com/bztMinamoto/p/9538115.html) 我蠢了…… 如果$a_{l} xor ...a_{r}=k$,那么只要 ...

  2. P4462 [CQOI2018]异或序列 莫队

    题意:给定数列 \(a\) 和 \(k\) ,询问区间 \([l,r]\) 中有多少子区间满足异或和为 \(k\). 莫队.我们可以记录前缀异或值 \(a_i\),修改时,贡献为 \(c[a_i\bi ...

  3. luogu P4462 [CQOI2018]异或序列 |莫队

    题目描述 已知一个长度为n的整数数列a1,a2,...,an,给定查询参数l.r,问在al,al+1,...,ar​区间内,有多少子序列满足异或和等于k.也就是说,对于所有的x,y (I ≤ x ≤ ...

  4. bzoj 5301: [Cqoi2018]异或序列 (莫队算法)

    链接:https://www.lydsy.com/JudgeOnline/problem.php?id=5301 题面; 5301: [Cqoi2018]异或序列 Time Limit: 10 Sec ...

  5. bzoj 5301 [Cqoi2018]异或序列 莫队

    5301: [Cqoi2018]异或序列 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 204  Solved: 155[Submit][Status ...

  6. 【洛谷P4462】异或序列

    题目大意:给定一个长度为 N 的序列,有 M 组询问,每组询问查询区间 [l,r] 内异或和等于给定常数 K 的区间组数. 题解:对于异或和问题,一般先进行前缀和处理,转化为两个点的的关系.因此,经过 ...

  7. BZOJ5301:[CQOI2018]异或序列(莫队)

    Description 已知一个长度为 n 的整数数列 a[1],a[2],…,a[n] ,给定查询参数 l.r ,问在 [l,r] 区间内,有多少连续子 序列满足异或和等于 k . 也就是说,对于所 ...

  8. [CQOI2018]异或序列 (莫队,异或前缀和)

    题目链接 Solution 有点巧的莫队. 考虑到区间 \([L,R]\) 的异或和也即 \(sum[L-1]~\bigoplus~sum[R]\) ,此处\(sum\)即为异或前缀和. 然后如何考虑 ...

  9. CQOI2018异或序列 [莫队]

    莫队板子 用于复习 #include <cstdio> #include <cstdlib> #include <algorithm> #include <c ...

随机推荐

  1. 微信小程序-form表单-获取用户输入文本框的值

    微信小程序-form表单-获取用户输入文本框的值 <input name='formnickname' class="textarea" placeholder=" ...

  2. 使用opencv库编译代码并运行

    安装Opencv之后,首先要写一份代码测试一下是否ok. 本文代码图像边沿检测的: #include <opencv2/highgui/highgui.hpp> #include < ...

  3. 10 种保护 Spring Boot 应用的绝佳方法

    原文:developer.okta.com/blog/2018/07/30/10-ways-to-secure-spring-boot 译文:www.jdon.com/49653 Spring Boo ...

  4. Mac OS Eclipse 调试快捷键不好使(失效)的情况

    Eclipse调试使用的F5  F6  F8一直都好用,结果一次调试后忽然不好使. 问题原因,尚未知晓. 解决办法,重启机器.

  5. 实现quartz定时器及quartz定时器原理介绍

    今天研究定时器,在网上看了一篇不错的文章,推荐给大家! 实现quartz定时器及quartz定时器原理介绍

  6. java模式—装饰者模式

    装饰者模式 1.意图: 动态地给一个对象添加一些额外的职责.就增加功能来说, Decorator模式相比生成子类更为灵活.该模式以对客 户端透明的方式扩展对象的功能. 2.适用环境 (1)在不影响其他 ...

  7. 自动化运维Ansible安装篇

    Ansible自动化工具之--部署篇 ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet.cfengine.chef.func.fabric)的优点,实现了 ...

  8. mysql 开发进阶篇系列 10 锁问题 (相同索引键值或同一行或间隙锁的冲突)

    1.使用相同索引键值的冲突 由于mysql 的行锁是针对索引加的锁,不是针对记录加的锁,所以虽然是访问不同行的记录,但如果是使用相同的索引键,是会出现锁冲突的.设计时要注意 例如:city表city_ ...

  9. Elasticsearch实践(三):Mapping

    版本:Elasticsearch 6.2.4. Mapping类似于数据库中的表结构定义,主要作用如下: 定义Index下字段名(Field Name) 定义字段的类型,比如数值型,字符串型.布尔型等 ...

  10. 非业务 Oracle SQL 语句备份

    1.创建一个将 Oracle 生成的 GUID 格式化为标准的 GUID 的函数 2.在 PLSQL 中测试并输出语句异常的语句块 3.在查询语句中日期的一种特殊表示方法 4.利用 ROWNUM 做分 ...