Getting same issue with JAVA. Getting TLE after 15-16 cases
I think your code counts no. of elements smaller than or equal to k. To find no. of elements smaller than k,
lower_bound must be used instead of
upper_bound in the code for query function.
Can u please share the implementation of segment tree with pbds ?