AT_arc232_a.Two in the Range
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an integer N, and M pairs of integers (L1,R1),(L2,R2),…,(LM,RM) satisfying 1≤Li<Ri≤N.
Determine whether there exists a length-N sequence of 0s and 1s, x=(x1,x2,…,xN), that satisfies all of the following conditions.
- xLi+xLi+1+⋯+xRi=2 for every i=1,2,…,M.
You are given T test cases; solve each of them.
给你一个整数 N,以及 M 对整数 (L1,R1),(L2,R2),…,(LM,RM),满足 1≤Li<Ri≤N。
判断是否存在一个长度为 N 的、由 0 和 1 构成的序列 x=(x1,x2,…,xN),使得以下条件全部成立:
- 对每个 i=1,2,…,M,均有 xLi+xLi+1+⋯+xRi=2。
你将得到 T 组测试数据;请分别求解每组数据。
输入格式
The input is given from Standard Input in the following format:
T
case1
case2
⋮
caseT
Each test case is given in the following format:
N M
L1 R1
L2 R2
⋮
LM RM
输入从标准输入中按以下格式给出:
T
case1
case2
⋮
caseT
每个测试用例按以下格式给出:
N M
L1 R1
L2 R2
⋮
LM RM
输出格式
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。
输入输出样例
输入#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
输出#1
No Yes Yes Yes No Yes
说明/提示
Sample 1 Explanation:
In the first test case, the first two conditions imply x1=x2=x3=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.
Constraints
- 1≤T≤250000
- 2≤N≤500000
- 1≤M≤500000
- 1≤Li<Ri≤N (1≤i≤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 解释:
在第一个测试用例中,前两个条件意味着 x1=x2=x3=1,但此时第三个条件不满足。因此,不存在满足所有条件的序列。
在第二个测试用例中,若 x=(0,1,0,1,0,0,1,0,1,0),则在指定区间 [1,4],[3,7],[6,10],[1,4],[2,6] 上的和均为 2。因此,该序列满足所有条件。
约束条件
- 1≤T≤250000
- 2≤N≤500000
- 1≤M≤500000
- 1≤Li<Ri≤N (1≤i≤M)
- 所有测试用例的 N 之和不超过 500000。
- 所有测试用例的 M 之和不超过 500000。
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?