SPOJ KQUERY NZEC

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.

I think Segment Tree will get TLE for this problems. I try to solve by Fenwick Tree and got AC. I think because of CPU which is used to judge that problem.

can anyone help??

It can be solved with Segment tree but fast i/o is required (even faster than scanf/printf).

no fast i/o is required, i have solved with segTree without fast i/o, i used offline programming

hmmmm maybe I should have done more constant optimization before using fast i/o :stuck_out_tongue: