CF617E XOR and Favorite Number
CF617E XOR and Favorite Number
已知一个序列 \(a_1,\ a_2,\ \cdots,\ a_n\) 和 \(k\) ,\(m\) 次询问给出 \(l,\ r\) ,求 \(\displaystyle\sum_{i=l}^r\sum_{j=i}^r[a_x\oplus a_{x+1}\oplus \cdots \oplus a_y=k]\)
\(n,\ m\leq10^5,\ 0\leq a_i,\ k\leq10^6\)
莫队
重题 bzoj5301 [CQOI2018]异或序列
考虑维护一个异或前缀和,问题就转化为了:区间 \([l-1,\ r]\) 中,有多少对数异或和为 \(k\)。莫队开桶记录即可
注意数组空间大小以及 \(long\ long\)
时间复杂度 \(O(n\sqrt n)\)
#include <bits/stdc++.h>
using namespace std;typedef long long ll;
const int maxn = 1e5 + 10;
int n, m, k, sz, a[maxn], bl[maxn], cnt[maxn * 20]; ll now, ans[maxn];
struct node {int l, r, tid;bool operator < (const node& o) const {return bl[l] != bl[o.l] ? l < o.l : r > o.r;}
} q[maxn];void add(int x) { now += cnt[x ^ k], cnt[x]++; }
void del(int x) { cnt[x]--, now -= cnt[x ^ k]; }int main() {scanf("%d %d %d", &n, &m, &k), sz = sqrt(n);for (int i = 1; i <= n; i++) {scanf("%d", a + i), a[i] ^= a[i - 1], bl[i] = (i - 1) / sz + 1;}for (int i = 1; i <= m; i++) {scanf("%d %d", &q[i].l, &q[i].r), q[i].l--, q[i].tid = i;}sort(q + 1, q + m + 1);int l = 0, r = -1;for (int i = 1; i <= m; i++) {while (q[i].l < l) add(a[--l]);while (q[i].r > r) add(a[++r]);while (q[i].l > l) del(a[l++]);while (q[i].r < r) del(a[r--]);ans[q[i].tid] = now;}for (int i = 1; i <= m; i++) {printf("%I64d\n", ans[i]);}return 0;
}
转载于:https://www.cnblogs.com/Juanzhang/p/10345401.html
CF617E XOR and Favorite Number相关推荐
- CF617E. XOR and Favorite Number
1 /* 2 CF617E. XOR and Favorite Number 3 http://codeforces.com/contest/617/problem/E 4 莫队算法 5 题意:求l, ...
- CodeForces 617 E. XOR and Favorite Number
题目链接: CodeForces 617 E. XOR and Favorite Number 题目描述: 给出n个数,m次查询,每次查询在区间[l, r]里面有多少对(i, j),满足ai ^ ai ...
- Codeforces617E XOR and Favorite Number (普通莫队)
题目链接: XOR and Favorite Number 2021.11.11更新了解题思路和代码 大致题意 给定一个长度为nnn的序列aaa, 和一个固定的数值kkk. 有mmm次询问, 每次询问 ...
- 【CF 617E】 XOR and Favorite Number (Mo's algorithm)
[CF 617E] XOR and Favorite Number (Mo's algorithm) E. XOR and Favorite Number time limit per test 4 ...
- XOR and Favorite Number(CF-617E)
Problem Description Bob has a favorite number k and ai of length n. Now he asks you to answer m quer ...
- Codeforces 617E XOR and Favorite Number
Discription Bob has a favorite number k and ai of length n. Now he asks you to answer m queries. Eac ...
- 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 莫队
https://vjudge.net/problem/CodeForces-617E 题目大意:给nnn个数,mmm个询问,以及一个数kkk,每次询问要输出[l,r][l,r][l,r]内满足a[i] ...
- CodeForces -617E XOR and Favorite Number(莫队)
题目链接:点击这里 题目大意: 给定一个长度为 nnn 的序列 a1,a2,...,ana_1,a_2,...,a_na1,a2,...,an ,再给出一个数字 kkk , mmm 组询问每组询 ...
最新文章
- oracle ora 14047,ORA-14047: ALTER TABLE|INDEX RENAME 不可以与其它分区组合
- 35.angularJS的ng-repeat指令
- 建站之前做好规划方案会为网站带来意外之喜
- [CF460E]Roland and Rose
- 计算机无法识别华为m3,华为8寸M3(非青春版)电脑连接问题报告
- Windows下mysql忘记密码的解决方法
- Boost.Asio的网络编程
- 用户界面草图设计工具-工具包和资源
- 为何只能在其关联的线程内启动timer?
- VC++ Tab Control控件的使用
- 转I give the orders around here.
- 免费下载思科 642-382考试题库
- 前端开发基础-JavaScript
- Adobe帝国的产品线
- 垃圾收集算法,垃圾收集器_实时垃圾收集
- 伽马变换的原理以及python实现
- Node开发实践总结-定时脚本的设计与实现
- 你听过哪些与房东有关的悲催的故事?
- 震惊:七成人对薪资不满,多劳并非能多得
- Metasploit(msf)利用ms17_010(永恒之蓝)出现Encoding::UndefinedConversionError问题
热门文章
- [BZOJ 3236] [Ahoi2013] 作业 [BZOJ 3809] 【莫队(+分块)】
- 安卓系统上的远程 JS 调试 Remote JavaScript Debugging on Android
- redis的密码验证,及哨兵的相关配置
- spring+websocket综合(springMVC+spring+MyBatis这是SSM框架和websocket集成技术)
- 用STATSVN统计公司SVN代码修改
- 书籍推荐-记这几年看的书
- 整理了二个基本的css库(高手请绕道)
- jdbc和odbc区别
- linux中rpm、yum、apt-get的关系
- 飞控计算机的作用,用于波音777飞机的主要飞控计算机