莫队算法。

#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. 移植Iperf到android 用来学习linux移植到安卓的例子

    Iperf移植记录 1.生成arm编译需要的头文件config.h ./configure --host=arm如果需要make clean make distclean2.增加Android.mk文 ...

  2. namenode ha

    http://blog.csdn.net/totxian/article/details/45248399 http://www.aboutyun.com/thread-13679-1-1.html ...

  3. ionic中 .col : 默认的定宽列

    .col : 默认的定宽列 在ionic的栅格中,每一行的各列默认是等宽的,这使得实现一个图片 浏览界面非常简单.下图是instagram app的截图: instagram <!DOCTYPE ...

  4. 【dfs 回溯】 zoj 1004

    题意:给出一个源字符串和一个目标字符串,打出所有符合stack操作的i,o串使得对于源字符串的操作能变为目标字符串 思路:搜索,回溯. 之前想过是不是队列,觉得不对那样bfs是求最优解了:也想过用结构 ...

  5. 字符函数库 cctype

    <cctype> (ctype.h) Character handling functions This header declares a set of functions to cla ...

  6. Spring Boot 系列教程6-全局异常处理

    @ControllerAdvice源码 package org.springframework.web.bind.annotation; import java.lang.annotation.Ann ...

  7. 字符串编码问题(Ascii、Unicode、UCS-2、GBK、UTF-8)

    1.字符编码的发展 第一阶段:ASCII阶段,(American Standard Code for Information Interchange, "美国信息交换标准码),计算机当时只支 ...

  8. 快学Scala-第三章 数组相关操作

    知识点: 1.定长数组 Array val nums = new Array[Int](10) //10个整数的数组,所有元素初始化为0 val a = new Array[String](10) / ...

  9. 最短路径算法——Dijkstra算法

    在路由选择算法中都要用到求最短路径算法.最出名的求最短路径算法有两个,即Bellman-Ford算法和Dijkstra算法.这两种算法的思路不同,但得出的结果是相同的. 下面只介绍Dijkstra算法 ...

  10. Problem A: 小火山的跳子游戏 多校训练2(小火山专场)(周期)

    题目链接:http://acm.zzuli.edu.cn/zzuliacm/problem.php?cid=1158&pid=0 zzuli 1905  题意:如果k=1的话是1,2,3,4. ...