How to do this question?

Please guide me on how to this question using segment trees.

Segment tree with node as a vector. Instead of a single element at every node, you need to have a vector which contains elements of that interval in sorted order or you can also use policy base data structure for the same. All you have to do is just binary search on that vector containing that interval and return the vector size - first index where you find the element or element greater than element given in query.

Sir I am getting TLE with this approach

my solution: https://ide.codingblocks.com/s/135727

STL has inbuilt merge function for merging.
See this implementation and you will get it.