第三届 AtCoder Japan Open -预选-(第 232 场 AtCoder Regular Contest++)
A
区间内恰有两个
Two in the Range
AtCoder
⌀ 2331
原题
←B →

区间内恰有两个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$。
AI (CI翻译)

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$。
  • 所有输入值均为整数。
AI (CI翻译)

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}_T
AI (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_M
AI (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翻译)

样例

Input #1
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
Output #1
No
Yes
Yes
Yes
No
Yes
In the first test case, the first two conditions imply $x_1=x_2=x_3=1$, but then the third condition is not satisfied. Thus, no sequence satisfies the conditions. In the second test case, if $x=(0,1,0,1,0,0,1,0,1,0)$, the sums over the specified intervals $[1,4],[3,7],[6,10],[1,4],[2,6]$ are all $2$. Thus, this sequence satisfies all the conditions.
题目信息
题号
arc232_a
时间限制
2 s
内存限制
1024 MB

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