XOR and Favorite Number CodeForces - 617E
a[i]^a[i+1]……a[j]=k;
处理前缀和pre[i]
那么上式可以表示为pre[i-1]^pre[j]=k;
#include<bits/stdc++.h>
using namespace std;
const int N=1<<20;
struct node{
int l,r;
int id;
}q[N];
int pos[N];
long long ans[N];
//每个前缀值出现的次数
long long flag[N];
int a[N];
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=1,r=0;
long long Ans=0;
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()
{
cin>>n>>m>>k;
int sz=sqrt(n);
for(int i=1;i<=n;i++)
{
cin>>a[i];
//处理前缀和
a[i]=a[i]^a[i-1];
//分块
pos[i]=i/sz;
}
for(int i=1;i<=m;i++)
{
cin>>q[i].l>>q[i].r;
q[i].id=i;
}
sort(q+1,q+1+m,cmp);
flag[0]=1;
for(int i=1;i<=m;i++)
{
while(l<q[i].l)
{
del(l-1);
l++;
}
while(l>q[i].l)
{
l--;
add(l-1);
}
while(r<q[i].r)
{
r++;
add(r);
}
while(r>q[i].r)
{
del(r);
r--;
}
ans[q[i].id]=Ans;
}
for(int i=1;i<=m;i++)
cout<<ans[i]<<endl;
return 0;
}
XOR and Favorite Number CodeForces - 617E的更多相关文章
- XOR and Favorite Number CodeForces - 617E -莫队-异或前缀和
CodeForces - 617E 给n个数, m个询问, 每次询问问你[l, r]区间内有多少对(i, j), 使得a[i]^a[i+1]^......^a[j]结果为k.(注意 i ! = j) ...
- XOR and Favorite Number Codeforces - 617E || [CQOI2018]异或序列
https://www.luogu.org/problemnew/show/P4462 http://codeforces.com/problemset/problem/617/E 这个是莫队裸题了吧 ...
- XOR and Favorite Number CodeForces - 617E(前缀异或+莫队)
题意原文地址:https://blog.csdn.net/chenzhenyu123456/article/details/50574169 题意:有n个数和m次查询,每次查询区间[l, r]问满足a ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 莫队算法初识~~CodeForces - 617E
E. XOR and Favorite Number time limit per test 4 seconds memory limit per test 256 megabytes input s ...
随机推荐
- 软件发布!DOTA2统计学
更新日志: 1.2 增加DOTABUFF作为数据源,可以与DOTAMAX切换 1.1 增加关于对话框 增加版本信息 修复列表框头的错误 受到 http://tieba.baidu.com/p/38 ...
- openresty http
openresty http openresty默认没有提供http客户端,需要第三方提供插件. 下载方式: wget https://raw.githubusercontent.com/pintsi ...
- MySQL会话控制限制登录次数
前言 一般我们开发环境的MySQL是没有配置登录保护的,但仅限于开发环境,正式环境是不允许无限制登录,存在很大的风险. MySQL 5.7 以后提供了Connection-Contro ...
- alert弹出窗口,点击确认后关闭页面
alert("点击确认后,关闭页面"); window.opener=null;window.top.open('','_self','');window.close(this);
- c++中多文件的组织
参考书目:visual c++ 入门经典 第七版 Ivor Horton著 第八章 根据书中例子学习使用类的多文件项目. 首先要将类CBox定义成一个连贯的整体,在CBox.H文件中写入相关的类定义, ...
- 3、IP地址划分
划分子网方法:1.你所选择的子网掩码将会产生多少个子网?:2 的x 次方(x 代表被借走的主机位数)2.每个子网能有多少主机?: 2 的y 次方-2(y 代表被借走之后剩余的主机位数)3.块大小:bl ...
- 基于HTTPS的接口测试——nginx配置SSL
目录 基于HTTPS的接口测试--nginx配置SSL 1. 背景 2. 所需环境与域名备案解析 2.1 云服务器 2.2 域名 2.3 SSL证书 2.4 网站备案 2.5 域名解析 3.nginx ...
- springboot使用servlet
基于注解方式: 基于配置类:
- tmobst3
1.(单选题)如果数据库是oracle,则generator属性值不可以使用(). A)native B)identity C)hilo D)sequence 2.(单选题)为了获得用户提交的表单参数 ...
- LUA学习笔记(第1-4章)
需要一种简单的脚本语言来代替批处理,它需要足够小巧,同时功能上也应该足够强劲,自然选择了LUA语言. 第一章 Hello World print('Hello World') print(" ...