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相关推荐

  1. CF617E. XOR and Favorite Number

    1 /* 2 CF617E. XOR and Favorite Number 3 http://codeforces.com/contest/617/problem/E 4 莫队算法 5 题意:求l, ...

  2. CodeForces 617 E. XOR and Favorite Number

    题目链接: CodeForces 617 E. XOR and Favorite Number 题目描述: 给出n个数,m次查询,每次查询在区间[l, r]里面有多少对(i, j),满足ai ^ ai ...

  3. Codeforces617E XOR and Favorite Number (普通莫队)

    题目链接: XOR and Favorite Number 2021.11.11更新了解题思路和代码 大致题意 给定一个长度为nnn的序列aaa, 和一个固定的数值kkk. 有mmm次询问, 每次询问 ...

  4. 【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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. codeforces 617E XOR and Favorite Number 莫队

    https://vjudge.net/problem/CodeForces-617E 题目大意:给nnn个数,mmm个询问,以及一个数kkk,每次询问要输出[l,r][l,r][l,r]内满足a[i] ...

  9. CodeForces -617E XOR and Favorite Number(莫队)

    题目链接:点击这里 题目大意: 给定一个长度为 nnn 的序列 a1,a2,...,ana_1,a_2,...,a_na1​,a2​,...,an​ ,再给出一个数字 kkk , mmm 组询问每组询 ...

最新文章

  1. oracle ora 14047,ORA-14047: ALTER TABLE|INDEX RENAME 不可以与其它分区组合
  2. 35.angularJS的ng-repeat指令
  3. 建站之前做好规划方案会为网站带来意外之喜
  4. [CF460E]Roland and Rose
  5. 计算机无法识别华为m3,华为8寸M3(非青春版)电脑连接问题报告
  6. Windows下mysql忘记密码的解决方法
  7. Boost.Asio的网络编程
  8. 用户界面草图设计工具-工具包和资源
  9. 为何只能在其关联的线程内启动timer?
  10. VC++ Tab Control控件的使用
  11. 转I give the orders around here.
  12. 免费下载思科 642-382考试题库
  13. 前端开发基础-JavaScript
  14. Adobe帝国的产品线
  15. 垃圾收集算法,垃圾收集器_实时垃圾收集
  16. 伽马变换的原理以及python实现
  17. Node开发实践总结-定时脚本的设计与实现
  18. 你听过哪些与房东有关的悲催的故事?
  19. 震惊:七成人对薪资不满,多劳并非能多得
  20. Metasploit(msf)利用ms17_010(永恒之蓝)出现Encoding::UndefinedConversionError问题

热门文章

  1. [BZOJ 3236] [Ahoi2013] 作业 [BZOJ 3809] 【莫队(+分块)】
  2. 安卓系统上的远程 JS 调试 Remote JavaScript Debugging on Android
  3. redis的密码验证,及哨兵的相关配置
  4. spring+websocket综合(springMVC+spring+MyBatis这是SSM框架和websocket集成技术)
  5. 用STATSVN统计公司SVN代码修改
  6. 书籍推荐-记这几年看的书
  7. 整理了二个基本的css库(高手请绕道)
  8. jdbc和odbc区别
  9. linux中rpm、yum、apt-get的关系
  10. 飞控计算机的作用,用于波音777飞机的主要飞控计算机