upper bound only works for sorted vector and in merge fucntion we are just merging the vectors srtted part is not taken into account
How this code handles the case for sorting
@vinishthanai
When we build the segment tree, we store the sorted portions of each range in the node of the segment tree. When we query, we call the upper bound on the node which lies in the required range. Thus, taking the count from each sorted segment of the required range(l, r), we are able to generate the answer.
If my answer if able to answer your question , please mark the doubt as resolved.
1 Like