CF1291B.Array Sharpening

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You're given an array a1,…,ana_1, \ldots, a_n of nn non-negative integers.

Let's call it sharpened if and only if there exists an integer 1≤k≤n1 \le k \le n such that a1<a2<…<aka_1 \lt a_2 \lt \ldots \lt a_k and ak>ak+1>…>ana_k \gt a_{k+1} \gt \ldots \gt a_n. In particular, any strictly increasing or strictly decreasing array is sharpened. For example:

  • The arrays [4][4], [0,1][0, 1], [12,10,8][12, 10, 8] and [3,11,15,9,7,4][3, 11, 15, 9, 7, 4] are sharpened;
  • The arrays [2,8,2,8,6,5][2, 8, 2, 8, 6, 5], [0,1,1,0][0, 1, 1, 0] and [2,5,6,9,8,8][2, 5, 6, 9, 8, 8] are not sharpened.

You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any ii (1≤i≤n1 \le i \le n) such that ai>0a_i \gt 0 and assign ai:=ai−1a_i := a_i - 1.

Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations.

给你一个包含 nn 个非负整数的数组 a1,…,ana_1, \ldots, a_n。

我们称该数组是尖锐的(sharpened),当且仅当存在某个整数 1≤k≤n1 \le k \le n,使得

a1<a2<…<ak且ak>ak+1>…>an.a_1 \lt a_2 \lt \ldots \lt a_k \quad \text{且} \quad a_k \gt a_{k+1} \gt \ldots \gt a_n.

特别地,任何严格递增或严格递减的数组都是尖锐的。例如:

  • 数组 [4][4]、[0,1][0, 1]、[12,10,8][12, 10, 8] 和 [3,11,15,9,7,4][3, 11, 15, 9, 7, 4] 是尖锐的;
  • 数组 [2,8,2,8,6,5][2, 8, 2, 8, 6, 5]、[0,1,1,0][0, 1, 1, 0] 和 [2,5,6,9,8,8][2, 5, 6, 9, 8, 8] 不是尖锐的。

你可以执行以下操作任意多次(包括零次):任选数组中一个严格大于 0 的元素,并将其减 1。形式化地说,你可以任选下标 ii(1≤i≤n1 \le i \le n),满足 ai>0a_i \gt 0,然后令 ai:=ai−1a_i := a_i - 1。

请判断:是否可以通过若干次(可能为零次)上述操作,将给定数组变为尖锐的数组?

输入格式

The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤15 0001 \le t \le 15\ 000) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤3⋅1051 \le n \le 3 \cdot 10^5).

The second line of each test case contains a sequence of nn non-negative integers a1,…,ana_1, \ldots, a_n (0≤ai≤1090 \le a_i \le 10^9).

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

输入包含多个测试用例。第一行包含一个整数 tt(1≤t≤15 0001 \le t \le 15\ 000),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤3⋅1051 \le n \le 3 \cdot 10^5)。

每个测试用例的第二行包含一个由 nn 个非负整数 a1,…,ana_1, \ldots, a_n 组成的序列(0≤ai≤1090 \le a_i \le 10^9)。

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

输出格式

For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise.

对于每个测试用例,如果可以使用上述操作将给定数组变为尖锐数组,则输出一行“Yes”(不带引号);否则输出一行“No”(不带引号)。

输入输出样例

  • 输入#1

    10
    1
    248618
    3
    12 10 8
    6
    100 11 15 9 7 8
    4
    0 1 1 0
    2
    0 0
    2
    0 1
    2
    1 0
    2
    1 1
    3
    0 1 0
    3
    1 0 1

    输出#1

    Yes
    Yes
    Yes
    No
    No
    Yes
    Yes
    Yes
    Yes
    No

说明/提示

In the first and the second test case of the first test, the given array is already sharpened.

In the third test case of the first test, we can transform the array into [3,11,15,9,7,4][3, 11, 15, 9, 7, 4] (decrease the first element 9797 times and decrease the last element 44 times). It is sharpened because 3<11<153 \lt 11 \lt 15 and 15>9>7>415 \gt 9 \gt 7 \gt 4.

In the fourth test case of the first test, it's impossible to make the given array sharpened.

在第一次测试的第一和第二个测试用例中,给定的数组已经是尖锐化的(sharpened)。

在第一次测试的第三个测试用例中,我们可以将数组变换为 [3,11,15,9,7,4][3, 11, 15, 9, 7, 4](将第一个元素减少 9797 次,将最后一个元素减少 44 次)。该数组是尖锐化的,因为 3<11<153 \lt 11 \lt 15 且 15>9>7>415 \gt 9 \gt 7 \gt 4。

在第一次测试的第四个测试用例中,无法使给定数组变为尖锐化的。

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

首页