Codeforces Round 1099 (Div. 2)
B
另一个排序问题
Another Sorting Problem
Codeforces
1100
原题
← AC →

另一个排序问题AI (CI翻译)

You are given an array $a_1, a_2, \ldots, a_n$. You can perform the following operation on this array at most once:

给定一个数组 $a_1, a_2, \ldots, a_n$。你至多可以对该数组执行一次以下操作:AI (CI翻译)

  • Choose a positive integer $k$, as well as a subsequence $b_1, b_2, \ldots, b_m$ of the array $a$$^{\text{∗}}$ and add $k$ to each element of this subsequence, that is, for each $i$ perform $a_{b_i} := a_{b_i} + k$.
  • 选择一个正整数 $k$,以及数组 $a$ 的一个子序列 $b_1, b_2, \ldots, b_m$$^{\text{∗}}$,将 $k$ 加到该子序列的每个元素上。也就是说,对每个 $i$ 执行 $a_{b_i} := a_{b_i} + k$。
AI (CI翻译)

You need to determine whether it is possible to sort the array in nondecreasing order by performing this operation at most once.

你需要判断,能否通过至多执行一次该操作,使数组按非递减顺序排列。AI (CI翻译)

$^{\text{∗}}$A sequence $b$ is a subsequence of a sequence $a$ if $b$ can be obtained from $a$ by the deletion of several (possibly, zero or all) element from arbitrary positions.

$^{\text{∗}}$如果序列 $b$ 可以通过删除序列 $a$ 中任意位置的若干个元素(可以删除零个或全部)得到,那么 $b$ 就是 $a$ 的一个子序列。AI (CI翻译)

Input

输入格式

AI (CI翻译)

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

每个输入包含多组测试用例。第一行包含测试用例数量 $t$($1 \le t \le 10^4$)。接下来是各测试用例的描述。AI (CI翻译)

In the first line of each test case, one integer $n$ is given ($1 \leq n \leq 2 \cdot 10^5$) — the length of the array $a$.

每个测试用例的第一行包含一个整数 $n$($1 \leq n \leq 2 \cdot 10^5$),表示数组 $a$ 的长度。AI (CI翻译)

In the second line of each test case, $n$ integers $a_1, a_2, \ldots, a_n$ are given ($1 \leq a_i \leq 10^9$).

每个测试用例的第二行包含 $n$ 个整数 $a_1, a_2, \ldots, a_n$($1 \leq a_i \leq 10^9$)。AI (CI翻译)

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

保证所有测试用例的 $n$ 之和不超过 $2 \cdot 10^5$。AI (CI翻译)

Output

输出格式

AI (CI翻译)

For each test case, print "Yes" if it is possible to sort the array by performing the operation at most once. Otherwise, print "No". You may print the answer in any case. For example, "YeS", "YES", "NO", "nO" will also be accepted.

对于每个测试用例,如果可以通过至多执行一次操作使数组有序,输出 "Yes";否则输出 "No"。答案不区分大小写。例如,"YeS"、"YES"、"NO"、"nO" 都会被接受。AI (CI翻译)

Note

说明

AI (CI翻译)

In the first test case, the array is already sorted, so the operation does not need to be performed at all.

在第一个测试用例中,数组已经有序,因此无需执行操作。AI (CI翻译)

In the second test case, it can be shown that it is impossible to sort the array using such an operation.

在第二个测试用例中,可以证明无法通过该操作使数组有序。AI (CI翻译)

In the third test case, choose $k = 6$ and choose the subsequence $[2, 4, 6]$ as $b$. Then after this operation, the array $a$ becomes $[8, \textbf{9}, 9, \textbf{10}, 10, \textbf{11}, 11]$ (the elements of the chosen subsequence are shown in bold).

在第三个测试用例中,选择 $k = 6$,并选择子序列 $[2, 4, 6]$ 作为 $b$。执行操作后,数组 $a$ 变为 $[8, \textbf{9}, 9, \textbf{10}, 10, \textbf{11}, 11]$(所选子序列中的元素以粗体标出)。AI (CI翻译)

样例

Input #1
8
4
1 2 3 4
5
10 5 9 4 4
7
8 3 9 4 10 5 11
6
5 3 10 5 9 7
3
2 1 1
5
2 1 1 2 1
3
3 1 2
5
2 1 2 3 1
Output #1
YES
NO
YES
NO
YES
YES
YES
NO
InputCopy OutputCopy
题目信息
题号
2231B
时间限制
1.5 s
内存限制
256 MB
标签
构造

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。