#P10852. 【MX-X2-T1】「Cfz Round 4」Awaken

    ID: 12324 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>模拟搜索数学Special JudgeO2优化高斯消元分类讨论梦熊比赛

【MX-X2-T1】「Cfz Round 4」Awaken

Background

Original link: https://oier.team/problems/X2A.


Can we wait until the moment the dream wakes up.

The image is unrelated to the problem solution. Source: Internet. Please delete if infringed. QWQ.

Problem Description

Yue had a dream. In the dream, she got an integer sequence a1,,ana_1, \ldots, a_n of length nn, where n5\bm{n \ge 5}.

Then she woke up. Yue forgot some elements of the sequence, leaving blanks. Luckily, Yue still remembers mm non-blank positions. Yue wants to fill in the blanks and restore the whole sequence.

Yue also remembers that the sequence in the dream had the following property: for all distinct indices x1,x2,x3,x4x_1, x_2, x_3, x_4 satisfying x2+x3=x1+x4x_2 + x_3 = x_1 + x_4, it always holds that ax2+ax3=ax1+ax4a_{x_2} + a_{x_3} = a_{x_1} + a_{x_4}.

Yue wants to know whether it is possible to restore a sequence that satisfies the property (if not, then she remembered it wrong). If possible, output Yes; otherwise output No.

Input Format

This problem has multiple test cases.

The first line contains an integer TT, the number of test cases.

Then each test case is given as follows:

  • The first line contains two integers n,mn, m, where n5n \ge 5, and mm is the number of positions in aia_i that are not blank.
  • The next mm lines each contain two integers pi,xip_i, x_i, meaning that apia_{p_i} is not blank and api=xia_{p_i} = x_i. It is guaranteed that all pip_i are pairwise distinct.

Output Format

For each test case, output a string Yes or No, indicating whether the original sequence exists.

In this problem, the output is case-insensitive. That is, yes, yeS, yEs, Yes, YEs, YeS, yES, YES are all considered Yes, and similarly for No.

3
5 3
1 1
4 4
5 5
6 6
1 1
3 7
2 4
5 5
4 1
6 4
5 0
Yes
No
Yes
1
5 2
1 -2
5 -10
Yes
2
9 6
1 -856675560
8 479857596
5 -92942328
4 -283875636
3 -474808944
9 670790904
10 7
4 -32297373
10 -633066970
9 831032854
5 -43726758
2 -699796467
1 -918486370
8 612342951
Yes
No

Hint

Sample Explanation #1

For the 11st test case, the current sequence is [1,?,?,4,5][1, ?, ?, 4, 5]. One possible original sequence is [1,2,3,4,5][1, 2, 3, 4, 5]. You can check that this sequence satisfies the property.

For the 22nd test case, the current sequence is [1,4,7,1,5,4][1, 4, 7, 1, 5, 4]. It can be proven that no original sequence satisfying the property exists. This sample reminds you that p\bm p is not necessarily given in increasing order.

For the 33rd test case, the current sequence is [?,?,?,?,?][?, ?, ?, ?, ?]. One possible original sequence is [0,0,0,0,0][0, 0, 0, 0, 0], and of course [1,1,1,1,1][-1, -1, -1, -1, -1] also works. This sample reminds you that mm can be 00, and the original sequence may contain negative numbers or 00.

Constraints

Let n\sum n denote the sum of nn within a single test file.

For all testdata, 1T4×1041 \le T \le 4 \times 10^4, 5n2×1055 \le n \le 2 \times 10^5, n2×105\sum n \le 2 \times 10^5, 0mn0 \le m \le n, 1pin1 \le p_i \le n, 109xi109-10^{9} \le x_i \le 10^{9}. It is guaranteed that within the same test case, all pip_i are pairwise distinct.

This problem uses bundled evaluation.

  • Subtask 1 (20 points): n2000n \le 2000 and m=nm = n.
  • Subtask 2 (30 points): n6n \le 6, x7|x| \le 7.
  • Subtask 3 (20 points): m=2m = 2.
  • Subtask 4 (30 points): no special constraints.

Translated by ChatGPT 5