Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
We move a horizontal line from the bottom of the chart to the top.
For each point we reach, the number of intersections might change, so we have to count it.
If a point we just reached is lower than its previous/next point, the number of intersections increases.
If a point we just reached is higher than its previous/next point, the number of intersections decreases.
There is also another solution using Fenwick Tree.