莫队算法。

#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std; const int maxn=+;
int a[maxn],pre[maxn];
long long cnt[*maxn];
int pos[maxn];
int n,m,k;
long long ans[maxn];
long long Ans;
int L,R;
struct X
{
int l,r,id;
}s[maxn]; bool cmp(const X&a,const X&b)
{
if(pos[a.l]==pos[b.l]) return a.r<b.r;
return a.l<b.l;
} int main()
{
scanf("%d%d%d",&n,&m,&k); int sz=sqrt(n);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
pre[i]=(pre[i-]^a[i]);
pos[i]=i/sz;
} for(int i=;i<=m;i++)
{
scanf("%d%d",&s[i].l,&s[i].r);
s[i].id=i;
} sort(s+,s++m,cmp);
Ans=; cnt[pre[s[].l-]]++; for(int i=s[].l;i<=s[].r;i++)
{
Ans=Ans+cnt[pre[i]^k];
cnt[pre[i]]++;
} L=s[].l; R=s[].r;
ans[s[].id]=Ans; for(int i=;i<=m;i++)
{
while(L<s[i].l)
{
cnt[pre[L-]]--;
Ans=Ans-cnt[pre[L-]^k];
L++;
} while(L>s[i].l)
{
L--;
Ans=Ans+cnt[pre[L-]^k];
cnt[pre[L-]]++;
} while(R<s[i].r)
{
R++;
Ans=Ans+cnt[pre[R]^k];
cnt[pre[R]]++;
} while(R>s[i].r)
{
cnt[pre[R]]--;
Ans=Ans-cnt[pre[R]^k];
R--;
}
ans[s[i].id]=Ans;
} for(int i=;i<=m;i++)
printf("%lld\n",ans[i]); return ;
}

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

  1. CodeForces - 617E XOR and Favorite Number (莫队+前缀和)

    Bob has a favorite number k and ai of length n. Now he asks you to answer m queries. Each query is g ...

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

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

  3. Codeforces 617E XOR and Favorite Number莫队

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

  4. Codeforces 617E XOR and Favorite Number(莫队算法)

    题目大概说给一个序列,多次询问区间异或和为k的连续子序列有多少个. 莫队算法,利用异或的性质,通过前缀和求区间和,先处理出序列各个前缀和,然后每次区间转移时维护i以及i-1前缀和为某数的个数并增加或减 ...

  5. codeforces 617E. XOR and Favorite Number 莫队

    题目链接 给n个数, m个询问, 每次询问问你[l, r]区间内有多少对(i, j), 使得a[i]^a[i+1]^......^a[j]结果为k. 维护一个前缀异或值就可以了. 要注意的是 区间[l ...

  6. [CQOI 2018]异或序列&[Codeforces 617E]XOR and Favorite Number

    Description 题库链接1 题库链接2 已知一个长度为 \(n\) 的整数数列 \(a_1,a_2,\cdots,a_n\) ,给定查询参数 \(l,r\) ,问在 \([l,r]\) 区间内 ...

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

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

  9. XOR and Favorite Number CodeForces - 617E -莫队-异或前缀和

    CodeForces - 617E 给n个数, m个询问, 每次询问问你[l, r]区间内有多少对(i, j), 使得a[i]^a[i+1]^......^a[j]结果为k.(注意 i ! =  j) ...

随机推荐

  1. linux配置使用外部smtp发送邮件

    mail命令需要设定mail.rc(或nail.rc)文件, set from=user@domain.comset smtp=smtp.domain.comset smtp-auth-user=us ...

  2. SQL中的左连接与右连接有什么区别,点解返回值会不同?(转)

    例子,相信你一看就明白,不需要多说 A表(a1,b1,c1) B表(a2,b2) a1 b1 c1 a2 b2 01 数学 95 01 张三 02 语文 90 02 李四 03 英语 80 04 王五 ...

  3. hadoop运行作业的脚本解析

    #!/usr/bin/env bash # Licensed to the Apache Software Foundation (ASF) under one or more # contribut ...

  4. 查找List中的最大最小值

    以下实例演示了如何使用 Collections 类的 max() 和 min() 方法来获取List中最大最小值: import java.util.*; public class Main { pu ...

  5. 下拉刷新和上拉加载 Swift

    转载自:http://iyiming.me/blog/2015/07/05/custom-refresh-and-loading/ 关于下拉刷新和上拉加载,项目中一直使用MJRefresh(原先还用过 ...

  6. ntp-keygen.c

    这个程序产生加密数据文件使用的的密码,遵循Autokey security protocol和NTPv4.文件名被名字和创建时间组成的头部当做前缀,后面跟有一个类型定义的描述符标签和PEM加密的数据结 ...

  7. jquery_api(事件一)

    一 .unload在火狐,谷歌无法弹出alerta是因为这两个浏览器默认组织alert弹出,unload事件可以进行一些对象销毁,事件解除绑定等清理工作. 如果你想在用户离开页面之前确认是否离开,最好 ...

  8. HDU - 1865 1string(大数)

    题目链接:http://acm.hust.edu.cn/vjudge/contest/121397#problem/F http://acm.hdu.edu.cn/showproblem.php?pi ...

  9. Compress a folder using powershell

    There are many ways to compress a folder using powershell: Method 1: Using System.IO.Compression and ...

  10. 介绍Python程序员常用的IDE和其它开发工具

    概述 “工欲善其事,必先利其器”,如果说编程是程序员的手艺,那么IDE就是程序员的吃饭家伙了. IDE 的全称是Integration Development Environment(集成开发环境), ...