QOJ.ac

QOJ

実行時間制限: 2 s メモリ制限: 256 MB 満点: 100

#8182. 袋中袋

統計

一位数学家每天都会去商店买一个袋子。这些袋子既美观又实用,所以数学家想把它们留作日后使用。他还想把这些袋子整理好:大袋子套大袋子,小袋子套小袋子。

第 $i$ 天买来的袋子(我们简称为袋子 $i$)在折叠状态下占据的体积为 $a_i$,在展开状态下占据的体积为 $b_i$(显然 $a_i < b_i$)。如果 $a_i < b_j$,则称袋子 $i$ 可以放入袋子 $j$ 中。数学家认为,如果袋子 $i$ 可以放入袋子 $j$ 中,且袋子 $j$ 也可以放入袋子 $i$ 中,那么袋子 $i$ 和袋子 $j$ 是相等的(应该放在一起)。

不幸的是,有时会出现三个袋子 $i, j, k$,使得袋子 $i$ 和袋子 $j$ 相等,袋子 $j$ 和袋子 $k$ 相等,但袋子 $i$ 和袋子 $k$ 却不相等!这让数学家非常害怕,因为它违背了他所知的等价关系。如果向他的收藏中添加一个新袋子会导致上述矛盾的三元组出现,他就会把这个新袋子扔掉,否则他会保留它(并且此后永远不会再扔掉它)。

你的任务是确定每个袋子是被保留了还是被扔掉了。

输入格式

第一行包含一个整数 $n$ —— 袋子的数量 ($1 \le n \le 3 \cdot 10^5$)。

接下来的 $n$ 行描述了这些袋子。第 $i$ 行包含两个整数 $a_i$ 和 $b_i$ —— 分别表示袋子 $i$ 在折叠和展开状态下的尺寸 ($1 \le a_i < b_i \le 10^9$)。

输出格式

输出 $n$ 行。如果数学家保留了袋子 $i$,则第 $i$ 行应包含单词 “KEPT”,否则输出 “THROWN AWAY”。

样例

输入 1

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

输出 1

KEPT
KEPT
KEPT
KEPT
THROWN AWAY
THROWN AWAY
THROWN AWAY
THROWN AWAY
KEPT
KEPT

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.