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

Автор mshubham, 12 лет назад, По-английски

Please Help to solve these SPOJ Problems

Make Them Equal

Update The Array !

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

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

Second problem is solving by segment tree, and I guess that in first problem there is always answer n — 1)

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

Can we solve "update the array" without use of segment tree

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

Generally, segment tree or fenwick tree is used when the array is updated and queried arbitrarily. i.e., Update is followed by query which is then followed by update.

In the second sum, there is first a number of updates. But after that, only querying and NO updates. So every element in its final state can be precomputed in O(n). For each query, it's then only O(1).

P.S.: Segment tree or Fenwick tree would also give the right answer but it would be slower and unnecessary.