#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.…
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…
题目链接: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…
任意门: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 yo…
题目链接:http://codeforces.com/contest/617/problem/E 题目大意:有n个数和m次查询,每次查询区间[l, r]问满足ai ^ ai+1 ^ ... ^ aj == k的(i, j)  (l <= i <= j <= r)有多少对. 解题思路:先预处理出一个前缀异或和数组sum数组,则a[l]^a[l+1]^a[l+2]……^a[r]就等于sum[r]^sum[l-1] 然后我们采用莫队算法,用一个数组cnt数组记录前缀和出现的次数 我们要找之前有…
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 pair li and ri and asks you to…
[Codeforces Round #340 (Div. 2)] vp了一场cf..(打不了深夜的场啊!!) A.Elephant 水题,直接贪心,能用5步走5步. B.Chocolate 乘法原理计数,统计连续的“0”到下一个“1”的个数,然后相乘(第一个1前面的0不能算上).当然还要特判全0的情况. C.Watering Flowers 这题1A.只要按照以到某一个喷泉的距离排序,然后枚举没有被这一个喷泉覆盖到的个数,然后通过第二个喷泉覆盖,贪心一下就好了. D.Polyline 题意杀,还…
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 a pai…
原来我直接学的是假的莫队 原题: 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…
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…
题目链接: 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…
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…
题目链接:http://codeforces.com/problemset/problem/242/E 给你n个数,m个操作,操作1是查询l到r之间的和,操作2是将l到r之间的每个数xor与x. 这题是线段树成段更新,但是不能直接更新,不然只能一个数一个数更新.这样只能把每个数存到一个数组中,长度大概是20吧,然后模拟二进制的位操作.仔细一点就行了. #include <iostream> #include <cstdio> #include <cmath> #incl…
C. Watering Flowers 题目连接: http://www.codeforces.com/contest/617/problem/C Descriptionww.co A flowerbed has many flowers and two fountains. You can adjust the water pressure and set any values r1(r1 ≥ 0) and r2(r2 ≥ 0), giving the distances at which t…
B. Chocolate 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co Bob loves everything sweet. His favorite chocolate bar consists of pieces, each piece may contain a nut. Bob wants to break the bar of chocolate into multiple pieces…
A. Elephant 题目连接: http://www.codeforces.com/contest/617/problem/A Descriptionww.co An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point x(x > 0) of the coord…
D. Polyline 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through…
题意与分析 (CodeForces 617C) 题意是这样的:一个花圃中有若干花和两个喷泉,你可以调节水的压力使得两个喷泉各自分别以\(r_1\)和\(r_2\)为最远距离向外喷水.你需要调整\(r_1,r_2\)的值使得所有的花都能被水所灌溉--换句话说,每一朵花要么到第一个喷泉的距离不超过\(r_1\),要么到第二个喷泉的距离不超过\(r_2\).当然如果两个条件都满足也是可以的.你需要用尽可能少的水来实现以上要求,也就是说使得\(r_1^2+r_2^2\)尽可能的小.找出这个最小值. 那么…
LINK:X-OR 本来是应该昨天晚上发的 可是昨天晚上 做这道题 写了一个分治做法 一直wa 然后查错 查不出来 心态崩了 想写对拍 发现交互库自己写不出来. 一系列sb操作 == 我都醉了. 今天重构了代码 换了另外一种做法就很快就过了. 考虑怎么做:求出所有位置上的数字是谁 光凭异或是很难异或出来的. 或许可以快速察觉到一个做法 对于每一位来做 然后 找到第i为为0的是谁 这样就得到了一个nlogn的做法. 会爆掉询问次数. 发现如果逐一找到每个位置上是谁的话 更快需要找到0所在. 考虑如…
题目大意:给你一个长度为n的序列,有m个询问,每次询问一个区间[L,R],表示这个区间内,有多少的a[i]^a[i+1].....^a[j]=k. 思路:莫队去搞就好了 我们定义pre[i]=a[1]^a[2]^....a[i],然后我们再去更新就好了,这里,我们定义区间[L,R]表示我们所要询问的区间即可.然后这里会有一个疑惑,就是为什么while(l<Q[i].l) { Delete(l-1); l++; }和while(l>Q[i].l) { l--; Updata(l-1); }是这样…
D. Polyline time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self…
B. Chocolate time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Bob loves everything sweet. His favorite chocolate bar consists of pieces, each piece may contain a nut. Bob wants to break the…
A. Elephant time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is…
Description A flowerbed has many flowers and two fountains. You can adjust the water pressure and set any values r1(r1 ≥ 0) and r2(r2 ≥ 0), giving the distances at which the water is spread from the first and second fountain respectively. You have to…
题意:一段01串 分割成段 每段只能有一个1 问一段串有多少种分割方式 思路:两个1之间有一个0就有两种分割方式,然后根据分步乘法原理来做. (不过这里有一组0 1 0这种数据的话就不好直接处理,所以遇到第一个1才开始标记) #include<iostream> using namespace std; int main() { ; int n; cin>>n; int a; ; ; ;i<n;i++) { cin>>a; if(s) { ){ l*=j+; j=…
题目链接 给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…
一直都说学莫队,直到现在才学,训练的时候就跪了   T_T,其实挺简单的感觉.其实训练的时候也看懂了,一知半解,就想着先敲.(其实这样是不好的,应该弄懂再敲,以后要养成这个习惯) 前缀异或也很快想出来,结果没弄好边界,也是对前缀异或和莫队的不熟练. CF 的E题,给定区间中有多少子区间个数异或等于k 容易想到的是预处理前缀异或值,求解区间[L, R]的贡献,相当于在前缀异或值[L - 1, R]中任取两个数,异或值等于k 知道区间[L, R]的贡献,可以O(1)知道[L - 1, R]和[L,…
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Victor adores the sets theory. Let us remind you that a set is a group of…
Codeforces Round #177 (Div. 1) A. Polo the Penguin and Strings 题意 让你构造一个长度为n的串,且里面恰好包含k个不同字符,让你构造的字符串字典序最小. 题解 先abababab,然后再把k个不同字符输出,那么这样就是最少 代码 #include<bits/stdc++.h> using namespace std; string s; int main() { int n,k; scanf("%d%d",&am…