It uses the O (n log n) -time algorithm, which uses a sweep line with the Fenwick tree.
Step 0: remapping coordinates
x- 0..n-1, . y-. , .
1:
. .
y. , . . , . , , . ( , + , - , ). (. , , .)
2:
, .
. , , , . y, y . , y . , y . , , , , . , , y ( ).
, . .