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

Автор Zacle07, история, 9 лет назад, По-английски

Here's the problem . I don't know why I'm getting WA on this problem. Here's my code. Your help will be highly appreciated

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

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

I haven't read all of your code, but this example (or something very similar) will break your code.

Look at the array [1, 1, 1, 2, 2, 2, 2, 3, 3, 3]. In the left half of the array 1 is the most frequent value (with frequency 3), in the right side 3 (with frequency 3). But in total the most frequent element is 2 with frequency 4. So return max(left, right); (line 23) will not work.

Usually this type of problem is solved using Mo's algorithm. I don't think that there is a fast solution using a Segment Tree.