AT_arc232_a.Two in the Range

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an integer NN, and MM pairs of integers (L1,R1),(L2,R2),…,(LM,RM)(L_1,R_1),(L_2,R_2),\ldots,(L_M,R_M) satisfying 1≤Li<Ri≤N1\leq L_i<R_i\leq N.

Determine whether there exists a length-NN sequence of 00s and 11s, x=(x1,x2,…,xN)x=(x_1,x_2,\ldots,x_N), that satisfies all of the following conditions.

  • xLi+xLi+1+⋯+xRi=2x_{L_i}+x_{L_i+1}+\cdots+x_{R_i}=2 for every i=1,2,…,Mi=1,2,\ldots,M.

You are given TT test cases; solve each of them.

给你一个整数 NN,以及 MM 对整数 (L1,R1),(L2,R2),…,(LM,RM)(L_1,R_1),(L_2,R_2),\ldots,(L_M,R_M),满足 1≤Li<Ri≤N1\leq L_i<R_i\leq N。

判断是否存在一个长度为 NN 的、由 00 和 11 构成的序列 x=(x1,x2,…,xN)x=(x_1,x_2,\ldots,x_N),使得以下条件全部成立:

  • 对每个 i=1,2,…,Mi=1,2,\ldots,M,均有 xLi+xLi+1+⋯+xRi=2x_{L_i}+x_{L_i+1}+\cdots+x_{R_i}=2。

你将得到 TT 组测试数据;请分别求解每组数据。

输入格式

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

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

Each test case is given in the following format:

NN MM
L1L_1 R1R_1
L2L_2 R2R_2
⋮\vdots
LML_M RMR_M

输入从标准输入中按以下格式给出:

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

每个测试用例按以下格式给出:

NN MM
L1L_1 R1R_1
L2L_2 R2R_2
⋮\vdots
LML_M RMR_M

输出格式

Output TT lines. The ii-th line should contain Yes if a sequence satisfying the conditions exists for the ii-th test case, and No otherwise.

输出 TT 行。第 ii 行应包含 Yes(如果第 ii 个测试用例存在满足条件的序列),否则包含 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=1x_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)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][1,4],[3,7],[6,10],[1,4],[2,6] are all 22. Thus, this sequence satisfies all the conditions.

Constraints

  • 1≤T≤2500001\leq T\leq 250000
  • 2≤N≤5000002\leq N\leq 500000
  • 1≤M≤5000001\leq M\leq 500000
  • 1≤Li<Ri≤N1\leq L_i<R_i\leq N (1≤i≤M)(1 \leq i \leq M)
  • The sum of NN over all test cases is at most 500000500000.
  • The sum of MM over all test cases is at most 500000500000.
  • All input values are integers.

样例 1 解释:
在第一个测试用例中,前两个条件意味着 x1=x2=x3=1x_1=x_2=x_3=1,但此时第三个条件不满足。因此,不存在满足所有条件的序列。

在第二个测试用例中,若 x=(0,1,0,1,0,0,1,0,1,0)x=(0,1,0,1,0,0,1,0,1,0),则在指定区间 [1,4],[3,7],[6,10],[1,4],[2,6][1,4],[3,7],[6,10],[1,4],[2,6] 上的和均为 22。因此,该序列满足所有条件。

约束条件

  • 1≤T≤2500001\leq T\leq 250000
  • 2≤N≤5000002\leq N\leq 500000
  • 1≤M≤5000001\leq M\leq 500000
  • 1≤Li<Ri≤N1\leq L_i<R_i\leq N (1≤i≤M)(1 \leq i \leq M)
  • 所有测试用例的 NN 之和不超过 500000500000。
  • 所有测试用例的 MM 之和不超过 500000500000。
  • 所有输入值均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页