QOJ.ac

QOJ

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

#1173. 知识就是……

Statistics

今天,Songjuk Haksa 计划发布 $N$ 个项目。Jongyoung 和他的朋友们不想做太多的工作,所以他们决定分担这些项目并完成它们。

项目 $i$ 可以在时间 $L_i$ 访问,并且必须在时间 $R_i$ 或之前完成。由于学生们的学习能力有限,完成一个项目会占用所有可用时间。

此外,一名学生不能同时处理多个项目,因此如果一名学生选择了两个项目 $i$ 和 $j$,则必须满足 $R_i < L_j$ 或 $R_j < L_i$。同时,学生们对繁重的工作兴趣不大,因此每名学生最多只会处理两个项目。

一群 $M$ 名优秀学生希望共同完成尽可能多的项目。请帮助他们决定每名学生需要完成哪些项目。如果存在多种可能的方式,你可以选择其中任意一种。

输入格式

第一行包含两个整数 $N$ 和 $M$,分别表示项目的数量和学生的数量($1 \le M \le N \le 3 \cdot 10^5$)。

接下来的 $N$ 行,每行包含两个整数 $L_i$ 和 $R_i$,表示第 $i$ 个项目的开始时间和结束时间($1 \le L_i < R_i \le 10^9$)。

输出格式

输出 $N$ 个整数。第 $i$ 个整数表示处理项目 $i$ 的学生编号(从 $1$ 到 $M$)。如果没有任何学生处理项目 $i$,则输出 $0$。

完成的项目数量必须尽可能多。如果存在多种可能的方案,输出其中任意一种即可。

样例

输入 1

7 5
9 10
7 9
3 4
9 10
2 6
8 9
5 8

输出 1

3 2 2 5 5 4 1

输入 2

2 2
1 2
3 4

输出 2

1 1

输入 3

2 1
1 2
2 3

输出 3

1 0

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.