#abc238e. E - Range Sums

E - Range Sums

Score : 500500 points

问题描述

Takahashi 拥有一个秘密整数序列 aa。已知该序列的长度为 NN

你想要猜出 aa 的具体内容。他承诺会给你以下 QQ 条额外信息。

  • ii 条信息:ali+ali+1++aria_{l_i}+a_{l_i+1}+\cdots+a_{r_i} 的值。

如果给出这 QQ 条承诺的信息,是否可能确定序列 aa 中所有元素之和,即 a1+a2++aNa_1+a_2+\cdots+a_N 呢?

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Takahashi has a secret integer sequence aa. You know that the length of aa is NN.

You want to guess the contents of aa. He has promised to give you the following QQ additional pieces of information.

  • The ii-th information: the value ali+ali+1++aria_{l_i}+a_{l_i+1}+\cdots+a_{r_i}.

Is it possible to determine the sum of all elements in aa, a1+a2++aNa_1+a_2+\cdots+a_N, if the QQ pieces of promised information are given?

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 1Qmin(2×105,N(N+1)2)1 \leq Q \leq \min(2 \times 10^5,\frac{N(N+1)}{2})
  • 1liriN1 \leq l_i \leq r_i \leq N
  • (li,ri)(lj,rj) (ij)(l_i,r_i) \neq (l_j,r_j)\ (i \neq j)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN QQ

l1l_1 r1r_1

l2l_2 r2r_2

\hspace{0.4cm}\vdots

lQl_Q rQr_Q

Output

If it is possible to determine the sum of all elements in aa, print Yes; otherwise, print No.

Sample Input 1

3 3
1 2
2 3
2 2

Sample Output 1

Yes

From the first and second information, we can find the value a1+a2+a2+a3a_1+a_2+a_2+a_3. By subtracting the value of a2a_2 from it, we can determine the value a1+a2+a3a_1+a_2+a_3.

Sample Input 2

4 3
1 3
1 2
2 3

Sample Output 2

No

We can determine the sum of the first 33 elements of aa, but not the sum of all elements.

Sample Input 3

4 4
1 1
2 2
3 3
1 4

Sample Output 3

Yes

The fourth information directly gives us the sum of all elements.

update @ 2024/3/10 10:17:33