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

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

There is n number of elements & two types of queries. 1st query: update an element by new value 2nd query: how many numbers are greater than k in l to r range.

My approach is by using PST for every 1 to i (1<=i<=n) build a seg tree between 1 to maxValue of elements. Then in the 2nd query, I just calculate how many numbers greater than k in (l-1)'th seg tree & r'th seg tree in o(log N) & give the difference between them.

But in the 1st query, I can't do it by O(log N)......

Here is the problem link: https://www.spoj.com/problems/KQUERY2/en/ My solution: https://ideone.com/mdJeU4

please help it to do it..........

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

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

You can try to use segment tree of Treaps. In this case each query will execute in: [number of segments] log(N) * log(N) [query to the Treap to get elements greater than k]