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

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

Problem: You are given an array consisting of n elements and q queries in the form of [L,R]. You have to output the maximum occurrences of a number in the segment [L,R] for each query.

How to solve these kind of problems using Segment Tree ?? I can solve this using sqrt decomposition, but got stuck trying to solve using segment tree.

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

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

Still thinking about how you would do it with a segment tree, but here is a way you can do it in log n:

Store each number in an array of vectors, with the array indexed by each value in the input array. (You can use a map if values are very large.) In the vector you store the index of the respective value. You can binary search for the lower bound and upper bound of the segment in the vector and subtract their indices to get the answer.

The problem is that update queries are slow.

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

Found a link to similar discussion here. http://mirror.codeforces.com/blog/entry/19710?#comment-245484

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

Read the solution for problem PATULJCI. I think that is what you need.