QOJ.ac

QOJ

Time Limit: 2.0 s Memory Limit: 1024 MB Total points: 100

#10006. 好三角形

Statistics

给定二维平面上的 $n$ 个不同的点。

我们定义两点 $P = (x_1, y_1)$ 和 $Q = (x_2, y_2)$ 之间的距离为 $d(P, Q) = |x_1 - x_2| + |y_1 - y_2|$。

称三个不同的点 $U, V, W$ 构成一个“好三角形”,如果存在一个点 $T$ 使得 $d(U, T) = d(V, T) = d(W, T)$。注意,$T$ 不一定是格点。

求由给定点集可以构成的“好三角形”的数量。

输入格式

第一行包含一个整数 $N$ ($3 \le N \le 5 \cdot 10^5$)。

接下来的 $N$ 行中,第 $i$ 行包含两个空格分隔的整数 $x_i$ 和 $y_i$,表示第 $i$ 个点的坐标为 $(x_i, y_i)$ ($-10^9 \le x_i, y_i \le 10^9$;若 $i \neq j$,则 $(x_i, y_i) \neq (x_j, y_j)$)。

输出格式

输出一个整数:由给定点集可以构成的“好三角形”的数量。

样例

样例输入 1

5
1 -1
1 5
5 7
1 3
4 2

样例输出 1

9

样例输入 2

10
-2 -1
-2 2
-1 -2
-1 -1
-1 1
0 1
1 -1
1 2
2 -1
2 1

样例输出 2

108

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.