[CQOI 2018]异或序列&[Codeforces 617E]XOR and Favorite Number
Description
已知一个长度为 \(n\) 的整数数列 \(a_1,a_2,\cdots,a_n\) ,给定查询参数 \(l,r\) ,问在 \([l,r]\) 区间内,有多少连续子序列满足异或和等于 \(k\) 。
CQOI 数据范围: \(1\leq n\leq 10^5, a_i,k\leq 10^5\)
CF 数据范围: \(1\leq n\leq 10^5, a_i,k\leq 10^6\)
Solution
撞题也是醉了...
莫队傻逼题,乱搞即可。
Code
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5+5, SIZE = 1<<20;
int n, m, k, lim, a[N], cnt[SIZE]; ll ans[N];
struct tt {
int l, r, id;
bool operator < (const tt &b) const {
return l/lim == b.l/lim ? r < b.r : l < b.l;
}
}b[N];
void work() {
scanf("%d%d%d", &n, &m, &k); lim = sqrt(n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]), a[i] ^= a[i-1];
for (int i = 1; i <= m; i++) scanf("%d%d", &b[i].l, &b[i].r), --b[i].l, b[i].id = i;
sort(b+1, b+m+1);
int curl = 1, curr = 0; ll sum = 0;
for (int i = 1; i <= m; i++) {
int l = b[i].l, r = b[i].r;
while (curr < r) sum += cnt[a[++curr]^k], ++cnt[a[curr]];
while (curl > l) sum += cnt[a[--curl]^k], ++cnt[a[curl]];
while (curr > r) --cnt[a[curr]], sum -= cnt[a[curr--]^k];
while (curl < l) --cnt[a[curl]], sum -= cnt[a[curl++]^k];
ans[b[i].id] = sum;
}
for (int i = 1; i <= m; i++) printf("%lld\n", ans[i]);
}
int main() {work(); return 0; }
[CQOI 2018]异或序列&[Codeforces 617E]XOR and Favorite Number的更多相关文章
- [ CQOI 2018 ] 异或序列
\(\\\) Description 给出一个长为 \(n\) 的数列 \(A\) 和 \(k\),多次询问: 对于一个区间 \([L_i,R_i]\),问区间内有多少个不为空的子段异或和为 \(k\ ...
- Codeforces 617E XOR and Favorite Number(莫队算法)
题目大概说给一个序列,多次询问区间异或和为k的连续子序列有多少个. 莫队算法,利用异或的性质,通过前缀和求区间和,先处理出序列各个前缀和,然后每次区间转移时维护i以及i-1前缀和为某数的个数并增加或减 ...
- Codeforces 617E XOR and Favorite Number莫队
http://codeforces.com/contest/617/problem/E 题意:给出q个查询,每次询问区间内连续异或值为k的有几种情况. 思路:没有区间修改,而且扩展端点,减小端点在前缀 ...
- CodeForces - 617E XOR and Favorite Number (莫队+前缀和)
Bob has a favorite number k and ai of length n. Now he asks you to answer m queries. Each query is g ...
- codeforces 617E. XOR and Favorite Number 莫队
题目链接 给n个数, m个询问, 每次询问问你[l, r]区间内有多少对(i, j), 使得a[i]^a[i+1]^......^a[j]结果为k. 维护一个前缀异或值就可以了. 要注意的是 区间[l ...
- CodeForces - 617E XOR and Favorite Number 莫队算法
https://vjudge.net/problem/CodeForces-617E 题意,给你n个数ax,m个询问Ly,Ry, 问LR内有几对i,j,使得ai^...^ aj =k. 题解:第一道 ...
- CodeForces 617E XOR and Favorite Number
莫队算法. #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> ...
- Codeforeces 617E XOR and Favorite Number(莫队+小技巧)
E. XOR and Favorite Number time limit per test 4 seconds memory limit per test 256 megabytes input s ...
- CODEFORCES 340 XOR and Favorite Number 莫队模板题
原来我直接学的是假的莫队 原题: Bob has a favorite number k and ai of length n. Now he asks you to answer m queries ...
随机推荐
- [c# 20问] 4.Console应用获取执行路径
一行代码可以搞定了~ static void GetAppPath() { string path = System.Reflection.Assembly.GetExecutingAssembly( ...
- jQuery插件开发的五种形态小结
关于jQuery插件的开发自己也做了少许研究,自己也写过多个插件,在自己的团队了也分享过一次关于插件的课.开始的时候整觉的很复杂的代码,现在再次看的时候就清晰了许多.这里我把我自己总结出来的东西分享出 ...
- Unity Shader序列帧动画学习笔记
Unity Shader序列帧动画学习笔记 关于无限播放序列帧动画的一点问题 在学shader的序列帧动画时,书上写了这样一段代码: fixed4 frag(v2f i){ // 获得整数时间 flo ...
- C#调用C++库知识点
DllImport方式: CharSet属性:Ansi短字节和Unicode长字节 CallingConvention属性:Cdecl清理和被调用方清理堆栈 EntryPoint属性:定位函数入口.如 ...
- c# list修改某一个属性的值
public class info() { public string name{get;set;} public string age{get;set;} } list<info> li ...
- powerviot install in sharepoint 2013
1.在app server安装powerviot for sharepoint,然后进行配置powerviot 2.powerviot配置之前需要设置security token service以及e ...
- STL在数组算法的使用
find(a:起始位置 , b: 终止位置 , c: 要查找的内容) ------>查找寻找内容的位置 count(a:起始位置 , b: 终止位置 , c: 要查找的内容) -- ...
- 对一致性hash原理的理解
一致性hash算法解决的核心问题是,当solt数发生变化的时候能够尽量少的移动数据.该算法最早在<Consistent Hashing and Random Trees:Distributed ...
- centos7启动顺序加密的问题
在上一篇博客中我们说的是如何进入单用户模式,这篇我主要来讲centos7启动加密. 首先我们来说centos的启动顺序: 上一篇我们所说的进入单用户模式,就是在boot loader 这一层次下进入的 ...
- Fiddler工具详细介绍
百度看到Fiddler工具的详细介绍,转载收藏,侵权删,原文地址:http://blog.csdn.net/qq_21445563/article/details/51017605 前部分讲解Fidd ...