QOJ.ac

QOJ

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

#6633. 考试要求

الإحصائيات

大学期末考试即将到来。共有 $N$ 场考试,每场考试 $i$ ($1 \le i \le N$) 在时间段 $[S_i, E_i]$ 内持续进行(包含端点)。要通过一场考试,你需要全程参加(参加考试的整个持续时间足以通过考试)。你只能参加互不重叠的考试。形式化地说,对于任意两场考试 $i$ 和 $j$,仅当闭区间 $[S_i, E_i]$ 和 $[S_j, E_j]$ 不重叠时,你才能同时参加这两场考试。例如,$[1, 3]$ 和 $[2, 5]$ 重叠。同样地,$[1, 3]$ 和 $[3, 10]$ 也重叠。但 $[1, 3]$ 和 $[4, 5]$ 不重叠。

为了毕业,你需要满足 $M$ 个要求,每个要求的形式为:至少通过考试 $A$ 或 $B$ 中的一场($1 \le A, B \le N$ 且 $A \neq B$)。

你需要满足所有要求,同时只能参加互不重叠的考试。请检查你是否能够毕业(输出 YES 或 NO,区分大小写)。

输入格式

第一行包含一个整数 $T$,表示测试用例的数量。接下来是各测试用例。 每个测试用例的第一行包含两个整数 $N$ 和 $M$。 接下来 $N$ 行,每行包含 2 个整数。第 $i$ 行包含 $S_i$ 和 $E_i$。 接下来 $M$ 行,每行包含 2 个整数 $A$ 和 $B$(即你必须至少通过 $A$ 或 $B$ 中的一场)。

数据范围

  • $1 \le T \le 100$
  • $1 \le N \le 100000$
  • $0 \le M \le 100000$
  • $0 \le S_i \le E_i \le 1000000000$
  • $1 \le A, B \le N$ 且 $A \neq B$
  • 所有测试用例中 $N$ 的总和不超过 $100000$
  • 所有测试用例中 $M$ 的总和不超过 $100000$

输出格式

对于每个测试用例,在新的一行中打印结果——如果能够毕业则输出 YES,否则输出 NO(区分大小写)。

样例

样例输入 1

2
3 1
1 5
2 7
10 11
2 1
3 3
1 5
2 7
5 7
1 2
2 3
3 1

样例输出 1

YES
NO

说明

  • 测试用例 1:共有 3 场考试和 1 个要求。你可以通过考试 1 或 2 中的任意一场来满足此要求并毕业。
  • 测试用例 2:共有 3 场考试和 3 个要求。所有 3 场考试彼此重叠,因此你最多只能参加 1 场考试。但要满足所有 3 个要求,你需要参加至少 2 场考试。因此无法毕业。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#127EditorialOpen题解jiangly2025-12-12 23:27:15View

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.