XOR and Favorite Number time limit per test: 4 seconds memory limit per test: 256 megabytes input: standard input output: standard output Bob has a favorite number k and ai of length n. Now he asks you to answer m queries. Each query is given by a pa…
E. XOR and Favorite Number 题目连接: http://www.codeforces.com/contest/617/problem/E Descriptionww.co Bob has a favorite number k and ai of length n. Now he asks you to answer m queries. Each query is given by a pair li and ri and asks you to count the n…
题目链接: E. XOR and Favorite Number time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Bob has a favorite number k and ai of length n. Now he asks you to answer m queries. Each query is given by…
题目链接:http://codeforces.com/problemset/problem/617/E E. XOR and Favorite Number time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Bob has a favorite number k and ai of length n. Now he asks y…
https://vjudge.net/problem/CodeForces-617E 题意,给你n个数ax,m个询问Ly,Ry,  问LR内有几对i,j,使得ai^...^ aj =k. 题解:第一道莫队题. 技巧:前缀亦或.flag数组:利用XOR的性质. 莫队的区间排序及处理. id的处理:因为排序打乱了询问顺序,所以用id记录原来的顺序. 四个月后的补充: 关于XOR的性质: x^k=y <=> x^y=k. 所以每次读入一个a[i],Ans +=flag[a[i]^k]. It wo…
http://codeforces.com/contest/617/problem/E 题意:给出q个查询,每次询问区间内连续异或值为k的有几种情况. 思路:没有区间修改,而且扩展端点,减小端点在前缀和的处理下都是O(n)的,使用莫队算法,每次移动区间时,注意计数是否先减. /** @Date : 2016-12-09-19.31 * @Author : Lweleth (SoungEarlf@gmail.com) * @Link : https://github.com/ * @Version…
原来我直接学的是假的莫队 原题: Bob has a favorite number k and ai of length n. Now he asks you to answer m queries. Each query is given by a pair li and ri and asks you to count the number of pairs of integers i and j, such that l ≤ i ≤ j ≤ r and the xor of the nu…
一直都说学莫队,直到现在才学,训练的时候就跪了   T_T,其实挺简单的感觉.其实训练的时候也看懂了,一知半解,就想着先敲.(其实这样是不好的,应该弄懂再敲,以后要养成这个习惯) 前缀异或也很快想出来,结果没弄好边界,也是对前缀异或和莫队的不熟练. CF 的E题,给定区间中有多少子区间个数异或等于k 容易想到的是预处理前缀异或值,求解区间[L, R]的贡献,相当于在前缀异或值[L - 1, R]中任取两个数,异或值等于k 知道区间[L, R]的贡献,可以O(1)知道[L - 1, R]和[L,…
题目链接 给n个数, m个询问, 每次询问问你[l, r]区间内有多少对(i, j), 使得a[i]^a[i+1]^......^a[j]结果为k. 维护一个前缀异或值就可以了. 要注意的是 区间[l, r], 我们需要将pre[l-1]......pre[r]都加进去, pre[l-1]不能少. #include <iostream> #include <vector> #include <cstdio> #include <cstring> #inclu…
#include<bits/stdc++.h> using namespace std; <<; 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.…