QOJ.ac

QOJ

Límite de tiempo: 5.0 s Límite de memoria: 1024 MB Puntuación total: 100 Hackeable ✓

#18465. 三场比赛

Estadísticas

上个月,有 $n$ 个人参加了三场比赛。这些人被用 $1$ 到 $n$ 的不同整数进行标记。在每场比赛中,所有人根据表现进行排序,并获得 $1$ 到 $n$ 的排名。排名越小(即越靠前),选手越优秀。任何一场比赛的排名中都没有并列情况。

今天,不再是 $n$ 个人同时参赛,而是两个人进行两两对决。在一场对决中,在三场比赛中至少赢下两场的人获得胜利。胜者随后继续与另一个人竞争。这变得非常有趣:即使一个人 $a$ 不能直接战胜另一个人 $b$,也有可能存在另一个人 $c$ 战胜了 $b$,而 $a$ 战胜了 $c$。这样,我们可以说 $a$ “间接”战胜了 $b$。甚至有可能两个人可以互相间接战胜对方!

正式地,如果 $a$ 在至少两场比赛中的排名比 $b$ 更靠前,则称人 $a$ 直接战胜人 $b$。此外,如果存在一个人的序列 $p_1, p_2, \cdots, p_k$ ($k \ge 2$),满足对于所有 $i = 1, \cdots, k - 1$,$p_i$ 直接战胜 $p_{i+1}$,且 $p_1 = a$ 且 $p_k = b$,则称 $a$ 间接战胜 $b$。

给定每个人在每场比赛中的排名,回答 $q$ 个询问,每个询问问人 $a$ 是否间接战胜人 $b$。

输入格式

第一行包含一个整数 $n$ ($2 \le n \le 2 \cdot 10^5$),表示人数。

接下来的 $n$ 行,每行包含三个整数,按人 $1$ 到人 $n$ 的顺序,分别表示每个人在三场比赛中的排名。对于每场比赛,从 $1$ 到 $n$ 的每个排名都恰好出现一次。

下一行包含一个整数 $q$ ($1 \le q \le 2 \cdot 10^5$),表示询问的数量。

接下来的 $q$ 行,每行包含两个整数 $a$ 和 $b$ ($1 \le a, b \le n, a \ne b$),询问人 $a$ 是否间接战胜人 $b$。

输出格式

输出 $q$ 行。第 $i$ 行应当为 YESNO。如果人 $a$ 间接战胜人 $b$,输出 YES,否则输出 NO

样例

输入样例 1

4
2 4 3
3 1 4
4 3 2
1 2 1
3
1 2
2 1
3 4

输出样例 1

YES
YES
NO

说明

人 1 直接(且间接)战胜人 2。人 2 没有直接战胜人 1,但人 2 直接战胜人 3,且人 3 直接战胜人 1,因此人 2 间接战胜人 1。

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.