题意:给定数列 \(a\) 和 \(k\) ,询问区间 \([l,r]\) 中有多少子区间满足异或和为 \(k\)。

莫队。我们可以记录前缀异或值 \(a_i\),修改时,贡献为 \(c[a_i\bigoplus k]\) 。

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#define R register int
using namespace std;
namespace Luitaryi {
inline int g() { R x=0,f=1;
register char s; while(!isdigit(s=getchar())) f=s=='-'?-1:f;
do x=x*10+(s^48); while(isdigit(s=getchar())); return x*f;
} const int N=100010;
int n,m,k,B,anss,a[N],c[N<<1],ans[N];
struct node { int l,r,id,pos;
inline bool operator < (const node& that) const
{return pos==that.pos?pos&1?r<that.r:r>that.r:pos<that.pos;}
}q[N];
inline void add(int x) {anss+=c[x^k],++c[x];}
inline void sub(int x) {--c[x],anss-=c[x^k];}
inline void main() {
n=g(),m=g(),k=g(); B=sqrt(n+1);
for(R i=1;i<=n;++i) a[i]=g()^a[i-1];
for(R i=1;i<=m;++i)
q[i].l=g()-1,q[i].r=g(),q[i].id=i,q[i].pos=q[i].l/B+1;
sort(q+1,q+m+1);
for(R i=1,l=1,r=0,LL,RR,id;i<=m;++i) {
LL=q[i].l,RR=q[i].r,id=q[i].id;
while(l<LL) sub(a[l++]); while(l>LL) add(a[--l]);
while(r<RR) add(a[++r]); while(r>RR) sub(a[r--]); ans[id]=anss;
} for(R i=1;i<=m;++i) printf("%d\n",ans[i]);
}
} signed main() {Luitaryi::main(); return 0;}

2019.11.25

P4462 [CQOI2018]异或序列 莫队的更多相关文章

  1. 洛谷P4462 [CQOI2018]异或序列(莫队)

    题意 题目链接 Sol 一开始以为K每次都是给出的想了半天不会做. 然而发现读错题了维护个前缀异或和然后直接莫队搞就行,. #include<bits/stdc++.h> #define ...

  2. luogu P4462 [CQOI2018]异或序列 |莫队

    题目描述 已知一个长度为n的整数数列a1,a2,...,an,给定查询参数l.r,问在al,al+1,...,ar​区间内,有多少子序列满足异或和等于k.也就是说,对于所有的x,y (I ≤ x ≤ ...

  3. bzoj 5301 [Cqoi2018]异或序列 莫队

    5301: [Cqoi2018]异或序列 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 204  Solved: 155[Submit][Status ...

  4. bzoj 5301: [Cqoi2018]异或序列 (莫队算法)

    链接:https://www.lydsy.com/JudgeOnline/problem.php?id=5301 题面; 5301: [Cqoi2018]异或序列 Time Limit: 10 Sec ...

  5. BZOJ5301:[CQOI2018]异或序列(莫队)

    Description 已知一个长度为 n 的整数数列 a[1],a[2],…,a[n] ,给定查询参数 l.r ,问在 [l,r] 区间内,有多少连续子 序列满足异或和等于 k . 也就是说,对于所 ...

  6. [CQOI2018]异或序列 (莫队,异或前缀和)

    题目链接 Solution 有点巧的莫队. 考虑到区间 \([L,R]\) 的异或和也即 \(sum[L-1]~\bigoplus~sum[R]\) ,此处\(sum\)即为异或前缀和. 然后如何考虑 ...

  7. CQOI2018异或序列 [莫队]

    莫队板子 用于复习 #include <cstdio> #include <cstdlib> #include <algorithm> #include <c ...

  8. 洛谷P4462 [CQOI2018]异或序列(莫队)

    打广告->[这里](https://www.cnblogs.com/bztMinamoto/p/9538115.html) 我蠢了…… 如果$a_{l} xor ...a_{r}=k$,那么只要 ...

  9. 【CQOI2018】异或序列 - 莫队

    题目描述 已知一个长度为n的整数数列 $a_1,a_2,...,a_n$​,给定查询参数l.r,问在 $a_l,a_{l+1},...,a_r$​ 区间内,有多少子序列满足异或和等于k.也就是说,对于 ...

随机推荐

  1. 47 容器(六)——HashMap

    HashMap的概念 HashMap底层实现了哈希表,这是一种非常重要的数据结构,对于以后我们理解很多技术都有帮助,例如 redis数据库的核心技术和HashMap一样,因此,非常有必要让大家理解. ...

  2. idea 代码热启动配置方法

    Restart Server:代码已更新重启tomcat服务器

  3. c#连接Access数据库及增删改查作

    access:版本2003(后缀.mdb,新版access可另存为2003兼容版) using: using System;using System.Data;using System.Windows ...

  4. (转)WEB服务器_IIS配置优化指南

    原文地址:https://www.cnblogs.com/heyuquan/p/deploy-iis-set-performance-guide.html 通常把站点发布到IIS上运行正常后,很少会去 ...

  5. webapi session

    webapi中使用session 修改global.cs里面的内容 using System; using System.Web; using System.Web.Routing; using Sy ...

  6. Ant Design Pro实现导出Excel

    react Ant Design ProUI框架导出Excel(只能导出当前列表数据) 插件安装 npm install js-export-excel 安装完成之后开始引入 import Expor ...

  7. 图解Apache Mina

    Apache MINA 是一个用于简化开发构建高性能.高可扩展的网络应用框架.通过JAVA NIO在各种传输协议(如:TCP/IP.UDP/IP)上提供抽象的事件驱动异步API Apache MINA ...

  8. Django:母版、继承、组件、自定义标签

    1.for循环应用 1.1for Variable Description forloop.counter 当前循环的索引值(从1开始) forloop.counter0 当前循环的索引值(从0开始) ...

  9. day31-python之内置函数

    1.udp多线程 import socketserver class MyServer(socketserver.BaseRequestHandler): def handle(self): prin ...

  10. spring 自定义schema 加载异常 White spaces are required between publicId and systemId.

    spring 项目启动报错 报错日志如下: Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreExcepti ...