B. Hemose Shopping
Hemose was shopping with his friends Samez, AhmedZ, AshrafEzz, TheSawan and O_E in Germany. As you know, Hemose and his friends are problem solvers, so they are very clever. Therefore, they will go to all discount markets in Germany.
Hemose has an array of integers. He wants Samez to sort the array in the non-decreasing order. Since it would be a too easy problem for Samez, Hemose allows Samez to use only the following operation:
Choose indices and such that , and . Then, swap elements and .
Can you tell Samez if there's a way to sort the array in the non-decreasing order by using the operation written above some finite number of times (possibly )?
Each test contains multiple test cases. The first line contains the number of test cases . Description of the test cases follows.
The first line of each test case contains two integers and .
The second line of each test case contains integers .
It is guaranteed that the sum of over all test cases doesn't exceed .
For each test case, you should output a single string.
If Samez can sort the array in non-decreasing order using the operation written above, output "YES" (without quotes). Otherwise, output "NO" (without quotes).
You can print each letter of "YES" and "NO" in any case (upper or lower).
4 3 3 3 2 1 4 3 1 2 3 4 5 2 5 1 2 3 4 5 4 1 2 3 4 4
NO YES YES YES
In the first test case, you can't do any operations.
In the second test case, the array is already sorted.
In the third test case, you can do the operations as follows:
- ,
- ,
- ,
- ,
- ,
- ,
(Here refers to swapping elements at positions , ).
0 Comments
If you have any doubts/suggestion/any query or want to improve this article, you can comment down below and let me know. Will reply to you soon.