题目链接

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. inline int read()
  5. {
  6. int x=,f=;char ch=getchar();
  7. while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
  8. while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
  9. return x*f;
  10. }
  11.  
  12. /********************************************************************/
  13.  
  14. const int maxn = 1e5+;
  15. int n, m, k;
  16. int a[maxn], belong[maxn];
  17. ll ans[maxn], flag[maxn*]; //注意这里的flag 要大大大大
  18. ll now;
  19.  
  20. struct node{
  21. int l, r;
  22. int id;
  23. }q[maxn];
  24.  
  25. bool cmp(node x, node y){
  26. if(belong[x.l] == belong[y.l])
  27. return x.r < y.r;
  28. return belong[x.l] < belong[y.l];
  29. }
  30.  
  31. void Update(int x){
  32. now += flag[a[x]^k];
  33. flag[a[x]]++;
  34. }
  35.  
  36. void Delete(int x){
  37. flag[a[x]]--;
  38. now -= flag[a[x]^k];
  39. }
  40.  
  41. int main(){
  42. n = read(); m = read(); k = read();
  43. int sz = ceil(sqrt(n));
  44. for(int i = ;i <= n;i++){
  45. a[i] = read();
  46. belong[i] = (i-)/sz;
  47. }
  48. //前缀异或
  49. for(int i = ;i <= n;i++){
  50. a[i] = a[i-]^a[i];
  51. }
  52. for(int i = ;i <= m;i++){
  53. q[i].l = read(); q[i].r = read();
  54. q[i].id = i;
  55. }
  56. sort(q+, q++m, cmp);
  57. int l = , r = ;
  58. now = ;
  59. flag[] = ;
  60. for(int i = ;i <= m;i++){
  61. int id = q[i].id;
  62.  
  63. //while里面的顺序是不能随意更改的
  64. while(l < q[i].l){
  65. Delete(l-);
  66. l++;
  67. }
  68. while(l > q[i].l){
  69. l--;
  70. Update(l-);
  71. }
  72. while(r < q[i].r){
  73. r++;
  74. Update(r);
  75. }
  76. while(r > q[i].r){
  77. Delete(r);
  78. r--;
  79. }
  80. ans[id] = now;
  81. }
  82. for(int i = ;i <= m;i++){
  83. cout << ans[i] << endl;
  84. }
  85. return ;
  86. }

E. XOR and Favorite Number (莫队板子题)的更多相关文章

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

  2. Codeforces Round #340 (Div. 2) E XOR and Favorite Number 莫队板子

    #include<bits/stdc++.h> using namespace std; <<; struct node{ int l,r; int id; }q[N]; in ...

  3. Codeforces617 E . XOR and Favorite Number(莫队算法)

    XOR and Favorite Number time limit per test: 4 seconds memory limit per test: 256 megabytes input: s ...

  4. Codeforces Round #340 (Div. 2) E. XOR and Favorite Number 莫队算法

    E. XOR and Favorite Number 题目连接: http://www.codeforces.com/contest/617/problem/E Descriptionww.co Bo ...

  5. codeforces 617E E. XOR and Favorite Number(莫队算法)

    题目链接: E. XOR and Favorite Number time limit per test 4 seconds memory limit per test 256 megabytes i ...

  6. Codeforces Round #340 (Div. 2) E. XOR and Favorite Number —— 莫队算法

    题目链接:http://codeforces.com/problemset/problem/617/E E. XOR and Favorite Number time limit per test 4 ...

  7. CodeForces - 617E XOR and Favorite Number 莫队算法

    https://vjudge.net/problem/CodeForces-617E 题意,给你n个数ax,m个询问Ly,Ry,  问LR内有几对i,j,使得ai^...^ aj =k. 题解:第一道 ...

  8. Codeforces 617E XOR and Favorite Number莫队

    http://codeforces.com/contest/617/problem/E 题意:给出q个查询,每次询问区间内连续异或值为k的有几种情况. 思路:没有区间修改,而且扩展端点,减小端点在前缀 ...

  9. E. XOR and Favorite Number 莫队 2038: [2009国家集训队]小Z的袜子(hose)

    一直都说学莫队,直到现在才学,训练的时候就跪了   T_T,其实挺简单的感觉.其实训练的时候也看懂了,一知半解,就想着先敲.(其实这样是不好的,应该弄懂再敲,以后要养成这个习惯) 前缀异或也很快想出来 ...

  10. SP3267 DQUERY - D-query 莫队板子题

    题意可见:https://www.luogu.com.cn/problem/SP3267 可在vj上提交:https://vjudge.net/problem/SPOJ-DQUERY 题意翻译 给出一 ...

随机推荐

  1. apache下实现301永久性重定向的方法

    因为博客是使用了www.php100.com作为博客域名,所以想实现php100.com全部重定向(跳转)到www.php100.com.同时按照google的建议,使用服务器端 301 重定向,为了 ...

  2. SAP 系统账期开关

    (1)OB52 财务账期-C 财务维护表 T001B[维护表T001B] (2)OB29 -C FI 财政年变式 (3)MMPV / MMRV -物料账期 MMPV 商品会计期间设置-结帐期间 [ 如 ...

  3. 【智能无线小车系列八】在树莓派上使用USB网卡

    在这个腾“云”驾“物”(云:云计算,物:物联网)的时代,什么都可以没有,就是不能没有网络,树莓派也离不开它.本章节将详细介绍如何将树莓派接入互联网,因为有一些后期将要使用到的小软件需要联网进行下载和安 ...

  4. PAT天梯赛 L2-026. 小字辈 【BFS】

    题目链接 https://www.patest.cn/contests/gplt/L2-026 思路 用一个二维vector 来保存 每个人的子女 然后用BFS 广搜下去,当目前的状态 是搜完的时候 ...

  5. Linux-正则表达式学习(精)

    正则表达式30分钟入门教程 来园子之前写的一篇正则表达式教程,部分翻译自codeproject的The 30 Minute Regex Tutorial. 由于评论里有过长的URL,所以本页排版比较混 ...

  6. POJ3279 Fliptile —— 状态压缩 + 模拟

    题目链接:http://poj.org/problem?id=3279 Fliptile Time Limit: 2000MS   Memory Limit: 65536K Total Submiss ...

  7. 模仿yui将css和js打包,加速网页速度

    如果你有机会用firebug看看自己网站的网络请求,你会发现请求数量之多超乎你的想象.为减少这个数量,有许多技术方案.比如yui的combo,会将所有需要的js混合成一个文件下载,现代web服务器好像 ...

  8. 「LuoguP2252」 取石子游戏(威佐夫博弈

    [P2252]取石子游戏 - 洛谷 题目背景 无 题目描述 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以 ...

  9. 洛谷P1967货车运输——倍增LCA

    题目:https://www.luogu.org/problemnew/show/P1967 就是倍增LCA的裸题,注意一些细节即可. 代码如下: #include<iostream> # ...

  10. win7 第一次装 mysql-5.7.16-winx64 ,不知道root 密码,该如何处理?

    转载请注明出处:http://blog.csdn.net/qq_26093511/article/details/52851811 ERROR 1045 (28000): Access denied ...