题目描述
The match is set and your team is ready to win!
The team has $N$ players, each with the ability $A_{i}$.
But you are not happy with the given playing order. You are wondering how to create a new order so that the player with lesser ability go earlier, i.e., in non-decreasing order.
In one move, you can break a suffix of any length of the array and attach it to the front. You can do the move as many times as you like.
For example, the Array $A = [1, 2, 3, 4, 5, 6]$ can become $A = [5, 6, 1, 2, 3, 4]$ in one move by breaking and reattaching the suffix of length $2$.
For each testcase, if the array can be sorted non-decreasingly, print YES and the minimum number of moves to do so. Otherwise, print NO.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
Each testcase contains two lines. The first line has a single integer $N$, denoting the number of players in the team.
The second list has $N$ space-separated integers of the array $A$, where $A_{i}$ represents the ability of the $i^{th}$ player
------ Output ------
Print a single line containing the string "YES" if the string can be sorted or "NO" if it does not (without quotes). If answer is yes, print a second line containing a single integer, the minimum number of moves.
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$ $1 ≤ T, N ≤ 3 \cdot 10^{5}$
$$ $0 ≤ A_{i} ≤ 10^{9}$
$$ The sum of all $N$ over all testcases $T$, does not exceed $3 \cdot 10^{5}$.
----- Sample Input 1 ------
2
2
1 2
3
2 1 3
----- Sample Output 1 ------
YES
0
NO
----- explanation 1 ------
Example Case 1: The array is already sorted non-decreasingly. Hence, 0 moves required.Example Case 2: We cannot satisfy the condition for the given array. Hence, answer is NO.
输入格式
见题面
输出格式
见题面