Please guide me on how to this question using segment trees.
How to do this question?
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.
STL has inbuilt merge function for merging.
See this implementation and you will get it.