CQOI2018异或序列 [莫队]
莫队板子 用于复习
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
#define Sqr(x) ((x)*(x))
using namespace std;
const int N = 1e5 + 5;
struct Q{
int x, y, id;
}q[N];
int n, m, k, res;
int cnt[N << 1], sum[N], a[N], ans[N];
int bl[N], blsize;
bool rule(Q x, Q y){return bl[x.x] == bl[y.x] ? x.y < y.y : x.x < y.x;}
inline void ins(int x){
res += cnt[k ^ sum[x]];
++cnt[sum[x]];
}
inline void del(int x){
--cnt[sum[x]];
res -= cnt[k ^ sum[x]];
}
int main() {
scanf("%d%d%d", &n, &m, &k);
blsize = sqrt(n);
bl[0] = 1;
for(int i = 1; i <= n; ++i){
scanf("%d", &a[i]);
sum[i] = sum[i - 1] ^ a[i];
bl[i] = i / blsize + 1;
}
for(int i = 1; i <= m; ++i)
scanf("%d%d", &q[i].x, &q[i].y), --q[i].x, q[i].id = i;
sort(q + 1, q + m + 1, rule);
int l = 1, r = 0;
for(int i = 1; i <= m; ++i){
while(l > q[i].x) ins(--l);
while(l < q[i].x) del(l++);
while(r > q[i].y) del(r--);
while(r < q[i].y) ins(++r);
ans[q[i].id] = res;
}
for(int i = 1; i <= m; ++i)
printf("%d\n", ans[i]);
return 0;
}
CQOI2018异或序列 [莫队]的更多相关文章
- 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 ...
- BZOJ5301:[CQOI2018]异或序列(莫队)
Description 已知一个长度为 n 的整数数列 a[1],a[2],…,a[n] ,给定查询参数 l.r ,问在 [l,r] 区间内,有多少连续子 序列满足异或和等于 k . 也就是说,对于所 ...
- 洛谷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 ...
- 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.也就是说,对于 ...
- BZOJ5301: [Cqoi2018]异或序列(莫队)
5301: [Cqoi2018]异或序列 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 400 Solved: 291[Submit][Status ...
随机推荐
- OpenCL中的half与float的转换
在kernel中使用half类型可以在牺牲一定精度的代价下来提升运算速度. 在kernel中, 可以比较方便的对half数据进行计算, 但在host上的, 对half的使用就没那么方便了. 查看cl_ ...
- Git 最佳实践:分支管理
5月份,为统一团队git分支管理规范,刚开始准备自己写,在网上搜了下,发现不少不错的git分支管理实践.最后我为团队选择了这个git分支管理实践 A successful Git branching ...
- C# 一般处理程序ashx接收服务端post过来json数据
这个和前端js的接收方式有点不一样,前端接收用request.form["xxx"]即可
- 关于C#传给视图的字符串带有Html转义字符的处理
public class PageBarHelper//分页类 { public static string GetPageBar(string requestHref,int totalCount, ...
- SQLServer之创建索引视图
索引视图创建注意事项 对视图创建的第一个索引必须是唯一聚集索引. 创建唯一聚集索引后,可以创建更多非聚集索引. 为视图创建唯一聚集索引可以提高查询性能,因为视图在数据库中的存储方式与具有聚集索引的表的 ...
- c/c++ 多线程 std::call_once的应用
多线程 std::call_once的应用 std::call_once的应用:类成员的延迟初始化,并只初始化一次.和static的作用很像,都要求是线程安全的,c++11之前在多线程的环境下,sta ...
- Flex builder4.6激活【转】
方法一: 1.到Adobe官网下载FlashBuilder 4.6 http://download.adobe.com/pub/adobe/flex/win/FlashBuilder_4_6_LS10 ...
- LeetCode算法题-Reverse String II(Java实现)
这是悦乐书的第256次更新,第269篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第123题(顺位题号是541).给定一个字符串和一个整数k,你需要反转从字符串开头算起的 ...
- 线程池工厂方法newScheduledThreadPool(),计划任务
package com.thread.test.ThreadPool; import java.util.concurrent.Executors; import java.util.concurre ...
- Dockerfile 规范
https://time-track.cn/compile-docker-from-source.html 参考 https://time-track.cn/install-docker-on-ubu ...