Getting runtime error repeatedly…Is it because of memory limit exceeded?? Or an invalid memory access(arrayindex out of bound exception) ??

BTW, the approach I used here is -

A segment tree where each node stores an sorted interval.

For a query i then join different disjoint intervals and then i perform a binary search over the newly formed interval to get number of elements which are greater than k.