![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
莫队算法
tomjobs
别慌,慌也没用
展开
-
BZOJ3585. mex(可持久化线段树,莫队分块,线段树离线操作)
Description 有一个长度为n的数组{a1,a2,…,an}。m次询问,每次询问一个区间内最小没有出现过的自然数。 Input 第一行n,m。 第二行为n个数。 从第三行开始,每行一个询问l,r。 Output 一行一个数,表示每个询问的答案。 Sample Input 5 5 2 1 0 2 1 3 3 2 3 2 4 1 2 3 5 Sample Output 1 2 3 0 3 Hint 数据规模和约定 对于100%的数据: 1<=n,m<=200000 0&l原创 2020-07-22 20:24:45 · 293 阅读 · 0 评论 -
Turing Tree HDU - 3333(求不同数的和,树状数组离线 / 莫队)
After inventing Turing Tree, 3xian always felt boring when solving problems about intervals, because Turing Tree could easily have the solution. As well, wily 3xian made lots of new problems about intervals. So, today, this sick thing happens again… Now gi原创 2020-06-19 21:29:04 · 248 阅读 · 0 评论 -
XOR and Favorite Number CodeForces - 617E(莫队算法)
Bob has a favorite number k and a i of length n. Now he asks you to answer m queries. Each query is given by a pair l i and r i 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 numbers a i, a i + 1,原创 2020-05-21 20:54:01 · 232 阅读 · 0 评论 -
2019CCPC湘潭邀请赛 Chika and Friendly Pairs(莫队+树状数组)
Problem Description Chika gives you an integer sequence a1,a2,…,an and m tasks. For each task, you need to answer the number of “friendly pairs” in a given interval. friendly pair: for two integers ai...原创 2020-04-03 19:32:31 · 336 阅读 · 0 评论 -
BZOJ2038 小Z的袜子(莫队算法)
作为一个生活散漫的人,小Z每天早上都要耗费很久从一堆五颜六色的袜子中找出一双来穿。 终于有一天,小Z再也无法忍受这恼人的找袜子过程,于是他决定听天由命。 具体来说,小Z把这N只袜子从1到N编号,然后从编号L到R的袜子中随机选出两只来穿。 尽管小Z并不在意两只袜子是不是完整的一双,甚至不在意两只袜子是否一左一右,他却很在意袜子的颜色,毕竟穿两只不同色的袜子会很尴尬。 你的任务便是告诉小Z,他有多大的...原创 2020-02-18 11:06:14 · 447 阅读 · 0 评论 -
SP3267 DQUERY - D-query(莫队算法,区间不同数)
题意: 询问区间有多少个不同的数。 思路: 莫队裸题。 十分神奇的算法,我觉得关键就是离线排序,但是左端点的判据是第几块(分块),右端点的判据是大小。就这么一点点小改动,大大减小了复杂度ORZ。 #pragma GCC optimize(2) #include <cstdio> #include <cstring> #include <algorithm> #i...原创 2020-02-17 21:38:16 · 217 阅读 · 0 评论