Strange Constellations (Constellation) : OIS2022 - Round 4
Strange Constellations (Constellation) : OIS2022 - Round 4
Therefore, he gives you the 2D map of the stars during one particular night, and he tells you that there
were N stars on the sky. Furthermore, he also tells you the position (xi , yi ) of each star.
Stefan is interested in finding parallel L-shaped constellations. A parallel L-shaped path is a sequence
of three stars which form an L-shape and each side is parallel to the coordinate axes. The L can have
its sides rotated, as long as it still forms an L. Furthermore, the L can’t be degenerated (i.e. a straight
line or a dot).
Help Stefan find the number of parallel L-shaped constellations in the given star map!
☞ Among the attachments of this task you may find a template file constellation.* with a
sample incomplete implementation.
Input
The first line contains the only integer N .
The next N line contains 2 integers xi and yi .
Output
You need to write a single line with an integer: the number of parallel L-shaped constellation.
Constraints
• 1 ≤ N ≤ 200 000.
• 1 ≤ xi , yi ≤ 200 000 for each i = 0 . . . N − 1.
constellation Page 1 of 2
Scoring
Your program will be tested against several test cases grouped in subtasks. In order to obtain the score
of a subtask, your program needs to correctly solve all of its test cases.
– Subtask 1 (0 points) Examples.
– Subtask 2 (25 points) N ≤ 200.
– Subtask 3 (40 points) N ≤ 2000.
– Subtask 4 (35 points) No additional limitations.
Examples
input output
6 4
5 5
8 5
5 8
3 3
5 1
0 5
Explanation
In the first sample case there are 4 L-shaped constellation.
y y
9 9
8 8
7 7
6 6
5 5
4 4
3 3
2 2
1 1
0 0
0 1 2 3 4 5 6 7 8 9 x 0 1 2 3 4 5 6 7 8 9 x
y y
9 9
8 8
7 7
6 6
5 5
4 4
3 3
2 2
1 1
0 0
0 1 2 3 4 5 6 7 8 9 x 0 1 2 3 4 5 6 7 8 9 x
constellation Page 2 of 2