莫队算法。

#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. centos7与centos6区别

    CentOS 7 vs CentOS 6的不同   (1)桌面系统[CentOS6] GNOME 2.x[CentOS7] GNOME 3.x(GNOME Shell)(2)文件系统[CentOS6] ...

  2. 8.1 sikuli报错: 提示没有对应的javaw

    对于sikuli,需要安装32位的jdk且不能高于1.7的版本. 对于64位系统的C盘,Program Files文件夹是64位的,Program File(x86)文件夹是32位的 需要安装一个32 ...

  3. 安装MSYS2过程遇到的问题及解决记录

    1.在安装结束后按照官方教程开始更新系统是遇到了如下的错误 could not open file /var/lib/pacman/sync/msys32.db: Unrecognized archi ...

  4. UVA 571 Jugs ADD18 小白书10 数学Part1 专题

    只能往一个方向倒,如c1=3,c2=5,a b从0 0->0 5->3 2->0 2->2 0->2 5->3 4->0 4->3 1->0 1- ...

  5. runtime获取一个控件的所有属性

    控件的有些属性API并没有开放,可以通过runtime查看: unsigned int count; Ivar *ivarList = class_copyIvarList([UITextField ...

  6. POJ 3468<线段树,区间add>

    题目连接 //位运算 k<<1 相当于 k*2 k<<1|1 相当于 k*2+1 /* 修改区间内的值,并且维护区间和. 详见代码 */ #include<cstdio& ...

  7. ViewPager和Fragment组合 v4包下的页面切换

    /* *主页面下 */ //-------------主页面下---------------------- package com.example.viewpagerfragment; import ...

  8. python 第三方库下载

    C:\Python27\Scripts 路径下: easy_install.exe: C:\Python27\Scripts>easy_install.exe pycrypto pip.exe: ...

  9. 第19章 网络通信----TCP程序设计基础

    TCP网络程序设计是指利用Socket类编写通信程序.利用TCP协议进行通信的两个应用程序是有主次之分的,一个称为服务器程序,另一个称为客户机程序,两者的功能和编写方法大不一样. 1.InetAddr ...

  10. decompile elf

    no way, try,objdump --disassemble <elf file>