[BZOJ2724][Violet 6]蒲公英

Posted Elder_Giang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[BZOJ2724][Violet 6]蒲公英相关的知识,希望对你有一定的参考价值。

2724: [Violet 6]蒲公英

Time Limit: 40 Sec  Memory Limit: 512 MB Submit: 2404  Solved: 825 [Submit][Status][Discuss]

Description

技术分享

 

Input

技术分享

修正一下

l = (l_0 + x - 1) mod n + 1, r = (r_0 + x - 1) mod n + 1

Output

技术分享

Sample Input

6 3
1 2 3 2 1 2
1 5
3 6
1 5

Sample Output

1
2
1

HINT

技术分享

修正下:

n <= 40000, m <= 50000

 
设$mode\left(A\right)$表示集合$A$的众数
那么有一个显然的定理为$mode\left(A\cup B\right)\in A\cup\left\{mode\left(B\right)\right\}$
 
需要离散化,时间复杂度$O\left(nlogn\right)$
分为$x$块
设$f[i][j]$为第i块到第j块的众数,通过枚举$i$来求,时间复杂度为$O\left(xn\right)$
对于每个询问$\left(l,r\right)$,把中间的整块里面的众数用$f$数组得到,然后边缘的暴力判断出现次数
而出现次数的求法为:对每个权值开一个vector记录出现位置,在里面二分
所以单次询问的复杂度为$O\left(\frac{nlogn}{x}\right)$
那么总时间复杂度为$O\left(nlogn\right)+O\left(xn\right)+O\left(\frac{mnlogn}{x}\right) \ge O\left(nlogn+n\sqrt{mlogn}\right)$
当且仅当$x=\sqrt{mlogn}$时等号成立
 






以上是关于[BZOJ2724][Violet 6]蒲公英的主要内容,如果未能解决你的问题,请参考以下文章

BZOJ2724[Violet 6]蒲公英 分块+二分

BZOJ 2724 2724: [Violet 6]蒲公英 (区间众数不带修改版本)

[bzoj2724] [Violet 6]蒲公英

bzoj 2724: [Violet 6]蒲公英

BZOJ2724: [Violet 6]蒲公英

BZOJ2724: [Violet 6]蒲公英