
分块 、莫队
Error Man
我是菜逼
展开
-
分块基础
分块基础块的个数:将 n 个元素分为块,每一块个元素,即 block = 块的数目:很显然每一块都是个元素,都知道除法是向下取整,所以还需要判断 n % block 是否等于0,不等于则++num 块的左右端点位置:为了比较方便的维护操作时的不完整的块,所以需要知道每一块的 左右端点,即 L 和 R 数组。对于第 i 块,其左右端点为 每个元素所属于的块号:当然了,...原创 2019-08-03 21:13:15 · 154 阅读 · 0 评论 -
Codeforces 940 F - Machine Learning(带修改莫队, 及注意事项)
F - Machine LearningYou come home and fell some unpleasant smell. Where is it coming from?You are given an arraya. You have to answer the following queries:You are given two integerslandr. L...原创 2019-08-06 21:07:04 · 284 阅读 · 0 评论 -
HYSBZ - 2120 数颜色 (带修莫队)
题目链接思路:带修改莫队在普通莫队的基础上增加了一个时间指针,对时间指针的操作和对 L , R 指针操作几乎相同,排序函数稍有变化。对于时间指针,新增一个 update 函数,具体实现见代码Code:#include<bits/stdc++.h>#define debug(x) cout << "[" << #x <<": " ...原创 2019-10-14 10:00:37 · 164 阅读 · 0 评论 -
Codeforces 86 D.Powerful array(莫队算法)
Powerful arrayAn array of positive integersa1, a2, ..., anis given. Let us consider its arbitrary subarrayal, al + 1..., ar, where1 ≤ l ≤ r ≤ n. For every positive integersdenote byKsthe num...原创 2019-08-06 11:19:49 · 282 阅读 · 0 评论 -
HYSBZ - 2038 小Z的袜子(hose) (莫队算法)
小Z的袜子(hose)作为一个生活散漫的人,小Z每天早上都要耗费很久从一堆五颜六色的袜子中找出一双来穿。终于有一天,小Z再也无法忍受这恼人的找袜子过程,于是他决定听天由命……具体来说,小Z把这N只袜子从1到N编号,然后从编号L到R(L尽管小Z并不在意两只袜子是不是完整的一双,甚至不在意两只袜子是否一左一右,他却很在意袜子的颜色,毕竟穿两只不同色的袜子会很尴尬。你的任务便是告诉小Z,他有多...原创 2019-08-06 10:09:01 · 257 阅读 · 0 评论 -
codeforces 617 E.XOR and Favorite Number(莫队算法)
E. XOR and Favorite NumberBob has a favorite numberkandaiof lengthn. Now he asks you to answermqueries. Each query is given by a pairliandriand asks you to count the number of pairs of in...原创 2019-08-05 23:02:07 · 173 阅读 · 0 评论 -
Libre OJ #6279 数列分块入门 3
思路:和数列分块2几乎一样,在 lower_bound 处理答案时有点区别。Code:#include<bits/stdc++.h>#define debug(x) cout << "[" << #x <<": " << (x) <<"]"<< endl#define pii pair<...原创 2019-08-04 22:26:41 · 197 阅读 · 1 评论 -
Libre OJ #6278. 数列分块入门 2
思路:正常分块,然后多开一个数组 b 复制 a,但是不同的是 b 数组中的每一块都是有序的。每一次更新之后,都需要对 b 中的改变的块都重新排序(若是完整的块就不需要),然后查询的时候,不完整的块暴力找,完整的块用lower_bound,注意lower_bound的是 c - tag[i]Code:#include<bits/stdc++.h>#define de...原创 2019-08-03 23:31:02 · 245 阅读 · 0 评论 -
Libre OJ #6277. 数列分块入门 1
Code:#include<bits/stdc++.h>#define debug(x) cout << "[" << #x <<": " << (x) <<"]"<< endl#define pii pair<int,int>#define clr(a,b) memset((a),...原创 2019-08-03 21:27:38 · 164 阅读 · 0 评论 -
多次询问 [l, r] 区间和为 0 (或给定数) 的最大长度(莫队)
题目大意:给 nnn 个数,有 mmm 个询问,每次询问给出区间 [l,r][l,r][l,r],回答区间 [l,r][l,r][l,r] 中和为 0 的最大长度。数据范围:1<=n,m<=500001 <= n,m <= 500001<=n,m<=50000思路: 区间和为 0 ,那么显然 利用前缀和判相等是最好的方法。...原创 2019-08-22 17:42:27 · 653 阅读 · 0 评论