QOJ.ac

QOJ

حد الوقت: 2.0 s حد الذاكرة: 512 MB مجموع النقاط: 100

#18347. 字典序最小子序列

الإحصائيات

每当 KAIST 的学生走出校园时,他们通常会沿着一条名为 无尽路(Endless Road)的直路前行。这个名字来源于大多数学生觉得这条路“没有尽头”。造成这种感觉的一个因素是这条路单调的风景。在这里,我们将无尽路建模为一条长度为 $10^9$ 的线段。直线上的位置可以用一个实数 $x \in [0, 10^9)$ 来表示。

为了解决这个问题,RUN@KAIST 的成员决定沿着这条路种植各种五彩缤纷的花朵。RUN@KAIST 的 $N$ 名成员从 $1$ 到 $N$ 进行编号。在上次的例会中,每个成员都被分配了直线上一个非空的区间 $[L_i, R_i)$,包含所有满足 $L_i \le x < R_i$ 的位置 $x$。

编号越大的成员在社团中承担的责任也越大。因此,区间的长度随着成员编号的增加而单调不减。换句话说,对于所有的 $1 \le i < j \le N$,有 $R_i - L_i \leq R_j - L_j$。

种植工作分 $N$ 轮进行。在每一轮中,我们会选择一名之前未被选择过的成员来种植花朵。被选中的成员将在其分配的区间 $[L_i, R_i)$ 内种植花朵,但其他成员已经种植过花朵的位置除外。

为了使工作分配更加公平,选择成员的方式如下:

  • 选择将要种植花朵数量最少的成员。这里,花朵的数量由该成员将要种植新花朵的区间总长度决定(该长度可能为零)。
  • 如果有多个这样的成员,选择其中编号最小的成员。

Jaeung 现在需要公布种植计划。为此,他必须根据上述选择规则,找到这 $N$ 名成员种植花朵的顺序。请帮助他完成这项工作。

输入格式

第一行包含一个整数 $N$($1 \leq N \leq 250\,000$)。

接下来的 $N$ 行,每行包含两个整数 $L_i$ 和 $R_i$($0 \le L_i < R_i \le 10^9$,且对于所有 $1 \le i < j \le N$,满足 $R_i - L_i \leq R_j - L_j$)。

所有区间都是互不相同的。换句话说,对于所有 $1 \le i < j \le N$,$(L_i, R_i) \neq (L_j, R_j)$。

输出格式

输出 $N$ 个整数,表示种植的顺序。第 $i$ 个整数表示在第 $i$ 轮中种植花朵的成员编号。

样例

输入 1

6
1 2
2 3
3 4
4 5
1 3
3 5

输出 1

1 2 5 3 4 6

输入 2

4
3 7
10 14
1 6
6 11

输出 2

1 3 2 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.