题意:很多询问,求每个询问下,有多少个区间,异或=k。

分析:异或也有前缀和。[L,R] = pre[R] ^ pre[L-1];

莫队算法:是莫涛队长发明的,一种改良版的暴力离线算法。

首先将问题重新排序,有生成树的,有简单版的分块,然后通过一个区间去递推另个一区间的值。

这里需要记录一下flag[ pre[i] ] 的个数。

#include <bits/stdc++.h>

using namespace std;

const int maxn = <<;
int a[maxn]; struct Node {
int l,r,id;
}Q[maxn]; int pos[maxn];
long long ans[maxn];
long long flag[maxn]; bool cmp(Node a,Node b) {
if(pos[a.l]==pos[b.l])
return a.r < b.r;
return pos[a.l] < pos[b.l];
} int n,m,k;
int L = ,R = ;
long long Ans; void add(int x) {
Ans+=flag[a[x]^k];
flag[a[x]]++;
} void del(int x) {
flag[a[x]]--;
Ans-=flag[a[x]^k];
} int main()
{
scanf("%d%d%d",&n,&m,&k);
int sz = sqrt(n);
for(int i=; i <= n; i++) {
scanf("%d",&a[i]);
a[i] = a[i]^a[i-];
pos[i] = i/sz;
} for(int i=; i<=m ;i++) {
scanf("%d%d",&Q[i].l,&Q[i].r);
Q[i].id = i;
} sort(Q+,Q+m+,cmp);
flag[] = ; for(int i=; i <=m; i++) { while(L<Q[i].l) {
del(L-);
L++;
} while(L>Q[i].l) {
L--;
add(L-);
} while(R<Q[i].r) {
R++;
add(R);
} while(R>Q[i].r) {
del(R);
R--;
} ans[Q[i].id] = Ans;
} for(int i=; i <= m; i++)
printf("%I64d\n", ans[i]); return ;
}

E. XOR and Favorite Number的更多相关文章

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

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

  2. Codeforeces 617E XOR and Favorite Number(莫队+小技巧)

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

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

  4. XOR and Favorite Number(莫队算法+分块)

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

  5. CF617E XOR and Favorite Number

    CF617E XOR and Favorite Number 已知一个序列 \(a_1,\ a_2,\ \cdots,\ a_n\) 和 \(k\) ,\(m\) 次询问给出 \(l,\ r\) ,求 ...

  6. XOR and Favorite Number (莫对算法)

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

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

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

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

  10. 题解-CF617E XOR and Favorite Number

    题面 CF617E XOR and Favorite Number 给定 \(n,m,k\) 和 \(n\) 个数的序列 \(a_i\),\(m\) 次求区间 \([l,r]\) 中异或值为 \(k\ ...

随机推荐

  1. linux对于zombie的处理

    @(Linux基础)[僵尸进程处理] 今天在服务器上推送项目的时候,突然发现很卡.就用top查看了一下,果然此事不简单啊. top - 10:39:16 up 20 days, 23:11, 2 us ...

  2. vue父子组件生命周期函数执行顺序

    vue父组件加载和销毁执行最后一个钩子函数之前先执行一遍子组件的钩子: 1.加载 父:beforecreate-created-beforeMount-(子:beforecreate-created- ...

  3. Bloom filter和Counting bloom filter

    Bloom filter原理: https://en.wikipedia.org/wiki/Bloom_filter 推导过程结合博客: https://blog.csdn.net/jiaomeng/ ...

  4. oracle 单实例DG(切换篇三)

    一,开篇 此篇操作承接上文,必须完成DG实例搭建完成方可有执行以下内容的实例 二,切换物理备库 one. oracle01库命令 select switchover_status from v$dat ...

  5. curl -w函数

    url_effective 最终获取的url地址,尤其是当你指定给curl的地址存在301跳转,且通过-L继续追踪的情形. http_code http状态码,如200成功,301转向,404未找到, ...

  6. python 爬虫系列01-连接mysql

    爬虫学习中......................................... import pymysql conn = pymysql.connect(host=',database ...

  7. Eclipse/Myeclipse/Scala IDEA for Eclipse里两种添加插件的方法(在线和离线)

    不多说,直接上干货! 方法1:在线安装 第一步,在eclipse菜单栏下,选中help ---->Install New Software 第二步,点击图中 add 添加软件下载地址 第三步 , ...

  8. 虚拟机xp系统中Oracle 10g的安装

    1 安装过程(11步) 2.如果是xp系统可以直接并双击解压目录下的setup.ext,出现安装界面,如下: 3.输入口令和确认口令,如:oracle,点击下一步,出现如下进度条. 注:此口令即是管理 ...

  9. 【问题记录】 Linux 安装 apache 遇到的一些问题

    以下为linux上安装apache时自己遇到的一些问题,记录在这,以后遇到时也会不定时更新... 一.安装Apache提示APR not found的解决办法 解决方法: 1. 网站 http://a ...

  10. [转] CentOS下添加用户并且让用户获得root权限

    http://www.centoscn.com/CentOS/config/2014/0810/3471.html 1.添加用户,首先用adduser命令添加一个普通用户,命令如下: #adduser ...