QOJ.ac

QOJ

시간 제한: 2.0 s 메모리 제한: 512 MB 총점: 100 해킹 가능 ✓

#12301. 收购

통계

一家新的 IT 公司最近在城里成立了办公室!他们的总部位于点 $(0, 0)$,园区是一个以 $(0, 0)$ 和 $(1, 1)$ 为顶点的矩形。园区目前非常小,还没有任何设施。然而,附近有很多设施。为什么不扩大园区,把它们都包含在内呢?

这些设施将被逐一占领并加入园区。在控制每个设施后,公司必须重建园区周围的围栏。围栏应该是包含总部和所有已占领设施的、边平行于坐标轴的最小矩形。

可以重复利用之前围栏的材料,但有时围栏的总长度可能会增加。在这种情况下,必须购买一些新材料。如果占领前的围栏长度为 $a$ 米,占领后变为 $b$ 米,则需要购买 $b - a$ 单位的材料。

很难证明大规模购买材料的必要性。请找到一种占领设施的顺序,使得占领后围栏长度的最大增量最小化。

建造初始围栏(大小为 4)所需的材料不计入增量,因为它是初始存在的。

输入格式

输入的第一行包含一个整数 $n$ ($1 \le n \le 3 \cdot 10^5$),表示设施的数量。接下来的 $n$ 行中,每行包含两个整数 $x_i$ 和 $y_i$ ($1 \le x_i, y_i \le 10^9$),表示第 $i$ 个设施的坐标。

允许两个设施位于同一位置,也允许任何设施初始时就已经在园区内。

输出格式

输出一个 $1$ 到 $n$ 的排列:表示占领设施的顺序。该顺序应使占领后围栏长度的最大增量最小化。设施按照输入中给出的顺序编号为 $1$ 到 $n$。

如果存在多种答案,输出其中任意一种即可。

样例

样例输入 1

3
1 2
4 4
3 1

样例输出 1

1 3 2

样例输入 2

4
1 4
2 3
3 2
4 1

样例输出 2

1 2 3 4

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.