Блог пользователя bihariforces

Автор bihariforces, история, 2 года назад, По-английски

Mode of an array is the most frequent element, mode frequency is frequency of most frequent element.

For example, $$$[1,3,5,5]$$$ has mode $$$5$$$ and it's frequency is $$$2$$$ so mode frequency of this array is $$$2$$$.

For an array of length $$$N$$$ we need to find sum of mode frequency of all subarrays.

Is there any way to do this better than $$$O(N^2)$$$?

  • Проголосовать: нравится
  • +32
  • Проголосовать: не нравится

»
2 года назад, скрыть # |
 
Проголосовать: нравится -14 Проголосовать: не нравится

A very similar problem was asked in Codechef Starters 136. A slight difference was that the string provided was binary, so there were only two elements you needed to keep a track of, but the overall process of implementation will be the same.

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Since there are at most $$$\sqrt N$$$ different frequencies, so first we collect them, then for each frequency $$$f$$$ scan array with two pointers counting start of $$$f$$$-segment and end, but I can't immediately see is clean implementation of this because there are many cases where segments start and end.