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

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

Hi! I need some ideas for the following problem.

Given an initial array of zeros and target array, and operation of adding 1 to range [l, r]. Find the minimum number of steps to reach the target array.

I am looking for a solution which is better than O(n^2).

Thanks!

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

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

Hi. Is there a link to the problem?

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

You need segment tree with (minimum, position) as values and recursive greedy solution, which get the range, find minimum on it, add (it's value minus already added) to the answer, and split recursion to the left and to the right of min element.