Codeforces Round 947 (Div. 1 + Div. 2)
A
Bazoka and Mocha's Array
Codeforces
800
原题
←B →
翻译中…

Mocha likes arrays, so before her departure, Bazoka gave her an array $a$ consisting of $n$ positive integers as a gift.

翻译中…

Now Mocha wants to know whether array $a$ could become sorted in non-decreasing order after performing the following operation some (possibly, zero) times:

翻译中…
  • Split the array into two parts — a prefix and a suffix, then swap these two parts. In other words, let $a=x+y$. Then, we can set $a:= y+x$. Here $+$ denotes the array concatenation operation.
翻译中…

For example, if $a=[3,1,4,1,5]$, we can choose $x=[3,1]$ and $y=[4,1,5]$, satisfying $a=x+y$. Then, we can set $a:= y + x = [4,1,5,3,1]$. We can also choose $x=[3,1,4,1,5]$ and $y=[\,]$, satisfying $a=x+y$. Then, we can set $a := y+x = [3,1,4,1,5]$. Note that we are not allowed to choose $x=[3,1,1]$ and $y=[4,5]$, neither are we allowed to choose $x=[1,3]$ and $y=[5,1,4]$, as both these choices do not satisfy $a=x+y$.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1\leq t\leq 1000$). The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($2\leq n\leq 50$) — the length of the array $a$.

翻译中…

The second line of each test case contains $n$ integers $a_1,a_2,\ldots,a_n$ ($1\leq a_i \leq 10^6$) — the elements of array $a$.

翻译中…

Output

翻译中…

For each test case, output "Yes" if $a$ could become non-decreasing after performing the operation any number of times, and output "No" if not.

翻译中…

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

翻译中…

Note

翻译中…

In the first test case, it can be proven that $a$ cannot become non-decreasing after performing the operation any number of times.

翻译中…

In the second test case, we can perform the following operations to make $a$ sorted in non-decreasing order:

翻译中…
  • Split the array into two parts: $x=[7]$ and $y=[9,2,2,3]$, then swap these two parts. The array will become $y+x = [9,2,2,3,7]$.
  • Split the array into two parts: $x=[9]$ and $y=[2,2,3,7]$, then swap these two parts. The array will become $y+x=[2,2,3,7,9]$, which is non-decreasing.
翻译中…

样例

Input #1
3
6
1 1 4 5 1 4
5
7 9 2 2 3
3
1 2 3
Output #1
No
Yes
Yes
InputCopy OutputCopy
题目信息
题号
1975A
时间限制
1 s
内存限制
256 MB
标签
暴力
贪心
模拟
排序

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