I am trying to solve this problem on spoj. The problem gives an input of n integers and then asks q queries which are of the form l r k and the program has to output number of elements greater than k in the subsequence al, al+1, ..., ar. I am using persistent segment trees to process queries online.but i am getting wrong answer. I am not able to find why my code fails.
Here's my code
Note: I know there's a way to solve this problem offline.But I am interested in online solution.