can someone give any hint how to approach https://cses.fi/problemset/task/2169 this problem ? I've tried sorting the starting points and the ending points and tried to observe if somehow I can merge them , but couldn't find any way . Will some special data structure need for this problem ?
I have solved this problem yesterday.
I sorted the array by the starting point.
Merge Sort Tree for the End Points.
I created a Merge Sort Tree using Segment Tree(This is very useful to answer queries such as how many elements are greater than or equal to $$$x$$$ in the interval $$$[L, R]$$$. Or How many elements less than or equal to $$$x$$$ in the interval $$$[L, R]$$$.
Note: also you can make the same thing using Fenwick tree. Read here...
Now Linear scan the sorted list, and for each point $$$(x, y)$$$ Find how many elements greater than or equal to $$$y$$$ to the left of this point (Using Merge Sort Tree), this number would be the number of points the current point is contained in, Similarly Now how many points the current point contain: Find how many elements less than or equal to $$$y$$$ in the right of this point.