QOJ.ac

QOJ

时间限制: 3 s 内存限制: 1024 MB 总分: 100

#3651. 距离

统计

曼哈顿市被规划为一个街道和大道组成的网格,街道呈南北走向,大道呈东西走向。街道从东向西编号,从 1 开始;大道从北向南编号,从 1 开始。每个交叉路口由街道编号和大道编号 $(s, a)$ 标记。两个交叉路口 $(s_1, a_1)$ 和 $(s_2, a_2)$ 之间的距离为 $|s_1 - s_2| + |a_1 - a_2|$。

你的公司在曼哈顿的不同交叉路口经营着几辆餐车,你希望它们分布得足够开,以免相互竞争。为了评估它们的分布情况,你决定计算所有不同的餐车对之间的总距离。总距离较小意味着平均而言,餐车对之间靠得太近了。

请问所有不同的餐车对之间的总距离是多少?

输入格式

第一行包含一个整数 $N$ ($2 \le N \le 200\,000$),表示餐车的数量。

接下来的 $n$ 行描述了餐车的位置。每行包含两个整数 $s$ ($1 \le s \le 1\,000\,000$),表示该餐车的街道编号,以及 $a$ ($1 \le a \le 1\,000\,000$),表示该餐车的大道编号。

输出格式

输出所有不同的餐车对之间的总距离。

样例

样例输入 1

3
1 1
4 5
2 3

样例输出 1

14

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.