Need help to solve Spoj KQUERY2 by Persistent Segment tree??

Правка en1, от _Nyu_, 2018-09-22 13:19:25

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..........

Теги persistent segment tree, #data structure

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский _Nyu_ 2018-09-22 13:19:25 694 Initial revision (published)