Here's the link to the code i wrote . It is giving TLE

Hi

@code026 your approach is wrong this question is k query on spoj, i have replied on your previous post also check that.

HINT

This is an offline approach.
Store the array elements and the queries in the same array(for this you may define your own class or structure) . You can see my structure in the code below.
Now, we sort this array in decreasing order (according to the value of the array elements and the k values of the queries) .
Now, just traverse this sorted array :
a. If the element is array element , update the binary indexed tree to have this element
at the given index .
b. If the element is a query <left,right,k> , make a query to find the number of elements in the segment tree between [left, right]. Store this information in our answer array at the location corresponding to the query number we are dealing with .
Finally, output this array .

pm me so that i can explain you.

Hit like if you get it
Cheers!

and you don’t have to create a new post for same doubt, you can reply on the same thread that would much easier for me and you to communicate.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

How can i solve this using segment tree? and not B.I.T.