I tried the same code but its throwing errors please help

Hello @chemant077

You should define the size of the vector<vector> tree like below
vector<vector> tree(4n)
4
n is the upper limit for the size of the segment tree

Here is the modified code
In this code I have implemented the upper bound function (by name greaterK) and the merge function on my own.

Let me know if you still need any help.