Rumb 需要帮忙AI (CI翻译)
Mr. Rumb visits a prosthetist because his arms have gone numb. The prosthetist can assemble replacements, but their numbered components are out of order. Apparently, even getting a helping hand requires some assembly.
Mr. Rumb 因双臂麻木前往义肢师处就诊。义肢师可以组装替代手臂,但这些编号组件的顺序乱了。显然,就连获得一只援手也需要先进行一番组装。AI (CI翻译)
Formally, the labels on the components form a permutation$^{\text{∗}}$ $p$ of length $n$. Mr. Rumb can program a machine to perform the following operation exactly once:
形式化地说,组件上的标签构成一个长度为 $n$ 的排列$^{\text{∗}}$ $p$。Mr. Rumb 可以编程让机器恰好执行一次以下操作:AI (CI翻译)
- choose an integer
$m$($1 \le m \le n$) and indices$i_1 \lt i_2 \lt \ldots \lt i_m$; - reverse the elements of
$p$at the chosen indices. More precisely, for every$j$from$1$to$m$, the element at index$i_j$moves to index$i_{m-j+1}$. All other elements remain unchanged.
- 选择一个整数
$m$($1 \le m \le n$)以及若干下标$i_1 \lt i_2 \lt \ldots \lt i_m$; - 将
$p$中这些下标处的元素逆序。更准确地说,对于从$1$到$m$的每个$j$,下标$i_j$处的元素会移动到下标$i_{m-j+1}$处。其他元素保持不变。
The chosen indices do not have to be consecutive. For example, suppose $p = [1, {\color{red}{6}}, 3, {\color{red}{4}}, 5, {\color{red}{2}}]$. If you choose indices $2$, $4$, and $6$, the elements shown in red are reversed, and $p$ becomes $[1, {\color{red}{2}}, 3, {\color{red}{4}}, 5, {\color{red}{6}}]$.
选出的下标不必连续。例如,假设 $p = [1, {\color{red}{6}}, 3, {\color{red}{4}}, 5, {\color{red}{2}}]$。如果选择下标 $2$、$4$ 和 $6$,则红色标出的元素会被逆序,$p$ 变为 $[1, {\color{red}{2}}, 3, {\color{red}{4}}, 5, {\color{red}{6}}]$。AI (CI翻译)
Determine whether Mr. Rumb can sort $p$ in increasing order.
判断 Mr. Rumb 是否能将 $p$ 按递增顺序排好。AI (CI翻译)
$^{\text{∗}}$A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array), and $[1,3,4]$ is also not a permutation ($n=3$ but there is $4$ in the array).
$^{\text{∗}}$长度为 $n$ 的排列是由 $1$ 到 $n$ 中 $n$ 个互不相同的整数按任意顺序组成的数组。例如,$[2,3,1,5,4]$ 是一个排列,但 $[1,2,2]$ 不是排列(数组中的 $2$ 出现了两次),$[1,3,4]$ 也不是排列($n=3$,但数组中出现了 $4$)。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 500$). The description of the test cases follows.
每个输入包含多组测试用例。第一行包含测试用例数 $t$($1 \le t \le 500$)。接下来是各测试用例的描述。AI (CI翻译)
The first line of each test case contains a single integer $n$ ($1 \le n \le 100$).
每个测试用例的第一行包含一个整数 $n$($1 \le n \le 100$)。AI (CI翻译)
The second line contains a permutation $p_1, p_2, \ldots, p_n$ of the integers from $1$ to $n$.
第二行包含一个由 $1$ 到 $n$ 中的整数构成的排列 $p_1, p_2, \ldots, p_n$。AI (CI翻译)
Output
输出格式
AI (CI翻译)For each test case, output YES if it is possible to sort $p$ in increasing order after performing exactly one operation. Otherwise, output NO.
对于每个测试用例,如果恰好执行一次操作后可以将 $p$ 按递增顺序排好,则输出 YES;否则输出 NO。AI (CI翻译)
You can output the answer in any case (upper or lower). For example, the strings yEs, yes, Yes, and YES will be recognized as positive responses.
答案可以使用任意大小写形式。例如,yEs、yes、Yes 和 YES 都会被识别为肯定回答。AI (CI翻译)
Note
说明
AI (CI翻译)In the first test case, choose the only index. Reversing a single element does not change the permutation, so the requirement to perform exactly one operation is satisfied.
在第一个测试用例中,选择唯一的一个下标。逆序单个元素不会改变排列,因此满足恰好执行一次操作的要求。AI (CI翻译)
In the second test case, choose indices $1$ and $4$. The resulting permutation is $[1, 2, 3, 4]$.
在第二个测试用例中,选择下标 $1$ 和 $4$。得到的排列为 $[1, 2, 3, 4]$。AI (CI翻译)
In the fifth test case, choose indices $2$, $4$, and $6$. Notice that the chosen indices are not consecutive.
在第五个测试用例中,选择下标 $2$、$4$ 和 $6$。注意,选出的下标并不连续。AI (CI翻译)
样例
5
1
1
4
4 2 3 1
4
3 4 1 2
5
2 1 3 5 4
6
1 6 3 4 5 2
YES
YES
NO
NO
YES
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。