CF1851D.Prefix Permutation Sums

普及-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Your friends have an array of nn elements, calculated its array of prefix sums and passed it to you, accidentally losing one element during the transfer. Your task is to find out if the given array can matches permutation.

A permutation of nn elements is an array of nn numbers from 11 to nn such that each number occurs exactly one times in it.

The array of prefix sums of the array aa — is such an array bb that bi=∑j=1iaj,1≤i≤nb_i = \sum_{j=1}^i a_j, 1 \le i \le n.

For example, the original permutation was [1,5,2,4,3][1, 5, 2, 4, 3]. Its array of prefix sums — [1,6,8,12,15][1, 6, 8, 12, 15]. Having lost one element, you can get, for example, arrays [6,8,12,15][6, 8, 12, 15] or [1,6,8,15][1, 6, 8, 15].

It can also be shown that the array [1,2,100][1, 2, 100] does not correspond to any permutation.

你的朋友有一个包含 nn 个元素的数组,计算了它的前缀和数组,并将该前缀和数组交给你,但在传输过程中意外丢失了一个元素。你的任务是判断所给的数组是否可能对应某个排列。

一个 nn 元排列是指由 11 到 nn 的 nn 个整数组成的数组,其中每个数恰好出现一次。

数组 aa 的前缀和数组定义为数组 bb,满足 bi=∑j=1iajb_i = \sum_{j=1}^i a_j,其中 1≤i≤n1 \le i \le n。

例如,原始排列为 [1,5,2,4,3][1, 5, 2, 4, 3],其前缀和数组为 [1,6,8,12,15][1, 6, 8, 12, 15]。若丢失其中一个元素,则可能得到如 [6,8,12,15][6, 8, 12, 15] 或 [1,6,8,15][1, 6, 8, 15] 这样的数组。

还可以证明,数组 [1,2,100][1, 2, 100] 并不对应任何排列。

输入格式

The first line contains a positive number tt (1≤t≤1041 \le t \le 10^4) — the number of test cases. The description of the test cases follows.

The first line of the description of each test case contains a positive number nn (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5) — the size of the initial array.

The second line of the description of each test case contains n−1n - 1 positive number aia_i (1≤ai≤10181 \le a_i \le 10^{18}), ai−1<aia_{i-1} \lt a_i — elements of the array of prefix sums.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个正整数 tt(1≤t≤1041 \le t \le 10^4)—— 测试用例的数量。随后是各测试用例的描述。

每个测试用例的描述的第一行包含一个正整数 nn(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5)—— 初始数组的大小。

每个测试用例的描述的第二行包含 n−1n - 1 个正整数 aia_i(1≤ai≤10181 \le a_i \le 10^{18}),满足 ai−1<aia_{i-1} \lt a_i —— 即前缀和数组的元素。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output "YES" if such a permutation exists, and "NO" otherwise.

You can output "YES" and "NO" in any case (for example, the strings "yEs", "yes" and "Yes" will be recognized as a positive response).

对于每个测试用例,如果存在这样的排列,则输出 “YES”,否则输出 “NO”。

你可以以任意大小写形式输出 “YES” 和 “NO”(例如,字符串 “yEs”、“yes” 和 “Yes” 均会被识别为肯定回答)。

输入输出样例

  • 输入#1

    12
    5
    6 8 12 15
    5
    1 6 8 15
    4
    1 2 100
    4
    1 3 6
    2
    2
    3
    1 2
    4
    3 7 10
    5
    5 44 46 50
    4
    1 9 10
    5
    13 21 36 42
    5
    1 2 3 1000000000000000000
    9
    9 11 12 20 25 28 30 33

    输出#1

    YES
    YES
    NO
    YES
    YES
    NO
    YES
    NO
    NO
    NO
    NO
    NO

说明/提示

In the fourth example, for example, the permutation [1,2,3,4][1, 2, 3, 4] is suitable. In the fifth example, for example, the permutation [2,1][2, 1] is suitable. In the seventh example, for example, the permutation [1,2,4,3][1, 2, 4, 3] is suitable.

在第四个例子中,例如,排列 [1,2,3,4][1, 2, 3, 4] 是可行的。在第五个例子中,例如,排列 [2,1][2, 1] 是可行的。在第七个例子中,例如,排列 [1,2,4,3][1, 2, 4, 3] 是可行的。

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

首页