Polaris.AI プログラミングコンテスト 2026(AtCoder Beginner Contest 457)
E
交叉桌布
Crossing Table Cloth
AtCoder
⌀ 1428
原题
←F →

交叉桌布AI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

There are $N$ cells arranged in a horizontal row. The $i$-th cell from the left $(1 \le i \le N)$ is called cell $i$.

有 $N$ 个单元格排成一行。从左起第 $i$ 个单元格 $(1 \le i \le N)$ 称为单元格 $i$。AI (CI翻译)

There are $M$ pieces of cloth. Laying cloth $i$ $(1 \le i \le M)$ covers cells $L_i$ through $R_i$.

有 $M$ 块布。铺放第 $i$ 块布 $(1 \le i \le M)$ 时,会覆盖从单元格 $L_i$ 到 $R_i$ 的所有单元格。AI (CI翻译)

Answer $Q$ queries. For the $q$-th query $(1 \le q \le Q)$, integers $S_q$ and $T_q$ are given, so answer the following problem.

请回答 $Q$ 个询问。对于第 $q$ 个询问 $(1 \le q \le Q)$,给定整数 $S_q$ 和 $T_q$,请解决以下问题。AI (CI翻译)

  • Determine whether it is possible to choose exactly two pieces of cloth from the $M$ pieces and lay them so that the following condition is satisfied.
  • Cells $S_q$ through $T_q$ are covered by at least one piece of cloth, and no other cells are covered by any cloth.
  • 判断是否可以从这 $M$ 块布中恰好选择两块铺放,使其满足以下条件。
  • 单元格 $S_q$ 到 $T_q$ 至少被一块布覆盖,且除此之外的其他单元格均不被任何布覆盖。
AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $1 \le N \le 2 \times 10^5$
  • $2 \le M \le 2 \times 10^5$
  • $1 \le L_i \le R_i \le N$
  • $1 \le Q \le 2 \times 10^5$
  • $1 \le S_q \le T_q \le N$
  • All input values are integers.
  • $1 \le N \le 2 \times 10^5$
  • $2 \le M \le 2 \times 10^5$
  • $1 \le L_i \le R_i \le N$
  • $1 \le Q \le 2 \times 10^5$
  • $1 \le S_q \le T_q \le N$
  • 所有输入值均为整数。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

The input is given from Standard Input in the following format:

输入从标准输入按以下格式给出:AI (CI翻译)

N M
L_1 R_1
L_2 R_2
\vdots
L_M R_M
Q
S_1 T_1
S_2 T_2
\vdots
S_Q T_Q

N M
L_1 R_1
L_2 R_2
\vdots
L_M R_M
Q
S_1 T_1
S_2 T_2
\vdots
S_Q T_Q
AI (CI翻译)

Output

输出格式

AI (CI翻译)

Output the answers for the queries, separated by newlines.

按换行分隔输出各个询问的答案。AI (CI翻译)

For each query, output Yes if it is possible to choose two pieces of cloth satisfying the condition, and No otherwise.

对于每个询问,如果可以选择满足条件的两块布,输出 Yes;否则输出 No。AI (CI翻译)

样例

Input #1
4 3
1 3
1 1
2 4
4
1 4
2 4
1 3
1 1
Output #1
Yes
No
Yes
No
For the first query, the condition can be satisfied by choosing cloth $1$ and cloth $3$. For the third query, the condition can be satisfied by choosing cloth $1$ and cloth $2$. For the second and fourth queries, no choice of two pieces of cloth can satisfy the condition.
Input #2
7 10
2 6
2 5
3 6
1 6
1 2
5 6
2 3
3 7
2 3
1 2
10
1 2
3 5
1 4
1 5
1 5
5 7
1 6
2 3
5 7
2 4
Output #2
Yes
No
No
Yes
Yes
No
Yes
Yes
No
No
题目信息
题号
abc457_e
时间限制
2.5 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。