区间内恰有两个AI (CI翻译)
Problem Statement
题目描述
AI (CI翻译)You are given an integer $N$, and $M$ pairs of integers $(L_1,R_1),(L_2,R_2),\ldots,(L_M,R_M)$ satisfying $1\leq L_i<R_i\leq N$.
给定一个整数 $N$,以及 $M$ 对整数 $(L_1,R_1),(L_2,R_2),\ldots,(L_M,R_M)$,满足 $1\leq L_i<R_i\leq N$。AI (CI翻译)
Determine whether there exists a length-$N$ sequence of $0$s and $1$s, $x=(x_1,x_2,\ldots,x_N)$, that satisfies all of the following conditions.
请判断是否存在一个长度为 $N$、由 $0$ 和 $1$ 组成的序列 $x=(x_1,x_2,\ldots,x_N)$,满足以下所有条件。AI (CI翻译)
$x_{L_i}+x_{L_i+1}+\cdots+x_{R_i}=2$for every$i=1,2,\ldots,M$.
- 对每个
$i=1,2,\ldots,M$,都有$x_{L_i}+x_{L_i+1}+\cdots+x_{R_i}=2$。
You are given $T$ test cases; solve each of them.
给定 $T$ 组测试用例,请分别求解。AI (CI翻译)
Constraints
约束条件
AI (CI翻译)$1\leq T\leq 250000$$2\leq N\leq 500000$$1\leq M\leq 500000$$1\leq L_i<R_i\leq N$$(1 \leq i \leq M)$- The sum of
$N$over all test cases is at most$500000$. - The sum of
$M$over all test cases is at most$500000$. - All input values are integers.
$1\leq T\leq 250000$$2\leq N\leq 500000$$1\leq M\leq 500000$$1\leq L_i<R_i\leq N$$(1 \leq i \leq M)$- 所有测试用例的
$N$之和不超过$500000$。 - 所有测试用例的
$M$之和不超过$500000$。 - 所有输入值均为整数。
Input
输入格式
AI (CI翻译)The input is given from Standard Input in the following format:
输入从标准输入按以下格式给出:AI (CI翻译)
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_TAI (CI翻译)
Each test case is given in the following format:
每组测试用例按以下格式给出:AI (CI翻译)
N M
L_1 R_1
L_2 R_2
\vdots
L_M R_M
N M
L_1 R_1
L_2 R_2
\vdots
L_M R_MAI (CI翻译)
Output
输出格式
AI (CI翻译)Output $T$ lines. The $i$-th line should contain Yes if a sequence satisfying the conditions exists for the $i$-th test case, and No otherwise.
输出 $T$ 行。第 $i$ 行应当包含 Yes,表示第 $i$ 组测试用例存在满足条件的序列;否则输出 No。AI (CI翻译)
样例
6
3 3
1 2
2 3
1 3
10 5
1 4
3 7
6 10
1 4
2 6
2 1
1 2
4 3
1 3
3 4
2 4
4 3
1 2
3 4
1 4
5 3
1 5
1 5
1 5
No
Yes
Yes
Yes
No
Yes
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。