QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 128 MB Points totaux : 100

#16240. 糖果机

Statistiques

在一个糖果工厂里,有一台神秘的机器。它生产美味的糖果,每颗糖果都与其他糖果略有不同。机器有一排输出槽,编号为 $1$ 到 $n$,糖果一准备好就会从这些槽中掉落。没有人真正知道机器是如何工作的,但在开始生产之前,它会打印一份清单,告诉工厂主每颗糖果将在何时从哪个槽掉落。

现在,工厂主可以安装自动货车,它们在输出槽下方移动以接住掉落的糖果。当然,任何糖果都不应该掉在地上变质。然而,由于运行货车的成本很高,工厂主希望安装尽可能少的货车。

编写一个程序,计算接住所有糖果所需的最少货车数量。此外,你的程序还应输出哪辆货车应该接住哪颗糖果。货车以每秒一个槽宽的速度运行。在生产过程开始之前,每辆货车都可以被移动到它应该接住第一颗糖果的槽。

输入格式

输入从标准输入读取,描述机器的一次生产过程。

第一行包含恰好一个整数 $n$,表示该过程中生产的糖果数量。

接下来的 $n$ 行,每行包含一对整数 $s_i$ 和 $t_i$,表示糖果 $i$ 的输出槽和掉落时间。每个数对 $(s_i, t_i)$ 都是唯一的。

输出格式

输出应写入到标准输出。

第一行包含恰好一个整数 $w$,表示接住所有糖果所需的最少货车数量。货车编号为 $1$ 到 $w$。

接下来的 $n$ 行指示哪辆货车将接住哪颗糖果。为此,这些行中的每一行都包含三个整数:某颗糖果 $j$ 的输出槽 $s_j$、掉落时间 $t_j$ 以及货车编号 $w(j)$,使得在时间 $t_j$ 时,货车 $w(j)$ 将位于槽 $s_j$ 处,从而能够接住糖果 $j$。

由于所有糖果都必须被接住,输入行中给出的每个槽和时间对必须在输出中恰好出现一次(可以以任何顺序)。如果存在多个解,输出其中任意一个。

样例

输入样例 1

5
1 1
2 3
1 5
3 4
2 6

输出样例 1

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

数据范围

  • $1 \le n \le 100\,000$
  • $0 \le s_i, t_i \le 1\,000\,000\,000$

子任务

  • 对于占总分 20% 的测试用例:$n \le 85$ 且 $w \le 4$。
  • 对于占总分 60% 的测试用例:$n \le 8\,000$。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

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.