题意:给定数列 \(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. python技巧 — 整合 User-Agent 大全汇总

    一.IE 浏览器 而IE各个版本典型的userAgent如下:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)Mozilla/4.0 (compat ...

  2. 同一个Tomcat部署多个springboot项目问题

    2018-12-13 10:37:21,412 ERROR [localhost-startStop-2] c.a.d.s.DruidDataSourceStatManager [DruidDataS ...

  3. IDEA使用@Data注解,类调用get、set方法标红的解决办法

    1.在setting中,下载lombok插件,安装完成后重启idea

  4. 简述几个css hack?【CSS】

    (1) 图片间隙  在div中插入图片,图片会将div下方撑大3px. hack1:将<div>与<img>写在同一行. hack2:给<img>添加display ...

  5. 【代码片段】定时记录CPU使用率并保存为CSV

    原文链接 : [https://blog.zhoutao123.com/#/blog/article/64])(https://blog.zhoutao123.com/#/blog/article/6 ...

  6. jenkins报错 Upgrading Jenkins. Failed to update the default Update Site 'default'. Plugi

    解决方案: jenkins\hudson.model.UpdateCenter.xml 文件, 将 url 中的 https://updates.jenkins.io/update-center.js ...

  7. 转 CentOS 初体验十四:阿里云安装Gitlab

        原文 https://blog.csdn.net/zhaoyanjun6/article/details/79144175 非Unix操作系统(Windows) GitLab是专为Unix操作 ...

  8. Python开发之路:目录篇

    第一部分:Python基础知识 本篇主要python基础知识的积累和学习,其中包括python的介绍.基本数据类型.函数.模块及面向对象等.  第一篇:Python简介  第二篇:Python基本知识 ...

  9. websocket之简易聊天室

    一,带昵称的群聊 #!/usr/bin/env python # -*- coding:utf8 -*- import json from flask import Flask, request, r ...

  10. [nginx] nginx源码分析--proxy模式下nginx的自动重定向auto_redirect

    描述 我们配置了一个proxy模式下的nginx, upstream backend-test { server ; } server { listen ; location = /nginx/hww ...