307806: CF1420A. Cubes Sorting

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Cubes Sorting

题意翻译

- 给你一个长度为 n 的序列 $a_{1 \cdots n}$,每次你可以交换相邻的两个数,如果你可以在 $\frac{n \cdot(n-1)}{2}-1$ 次内使得数列有序(单调不减),输出 `YES`,否则输出 `NO`。 - **多组数据** , 保证 $1 \leq t \leq 1000 , \sum ^{t}_{i=1}n \leq 10^5 , n \le 5 \cdot 10^4,1 \leq a_i \leq 10^9$。 - by 226148

题目描述

For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for?Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got one hour! Solve it! Wheatley decided to try to make a test chamber. He made a nice test chamber, but there was only one detail absent — cubes. For completing the chamber Wheatley needs $ n $ cubes. $ i $ -th cube has a volume $ a_i $ . Wheatley has to place cubes in such a way that they would be sorted in a non-decreasing order by their volume. Formally, for each $ i>1 $ , $ a_{i-1} \le a_i $ must hold. To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any $ i>1 $ you can exchange cubes on positions $ i-1 $ and $ i $ . But there is a problem: Wheatley is very impatient. If Wheatley needs more than $ \frac{n \cdot (n-1)}{2}-1 $ exchange operations, he won't do this boring work. Wheatly wants to know: can cubes be sorted under this conditions?

输入输出格式

输入格式


Each test contains multiple test cases. The first line contains one positive integer $ t $ ( $ 1 \le t \le 1000 $ ), denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $ n $ ( $ 2 \le n \le 5 \cdot 10^4 $ ) — number of cubes. The second line contains $ n $ positive integers $ a_i $ ( $ 1 \le a_i \le 10^9 $ ) — volumes of cubes. It is guaranteed that the sum of $ n $ over all test cases does not exceed $ 10^5 $ .

输出格式


For each test case, print a word in a single line: "YES" (without quotation marks) if the cubes can be sorted and "NO" (without quotation marks) otherwise.

输入输出样例

输入样例 #1

3
5
5 3 2 1 4
6
2 2 2 2 2 2
2
2 1

输出样例 #1

YES
YES
NO

说明

In the first test case it is possible to sort all the cubes in $ 7 $ exchanges. In the second test case the cubes are already sorted. In the third test case we can make $ 0 $ exchanges, but the cubes are not sorted yet, so the answer is "NO".

Input

题意翻译

- 给你一个长度为 n 的序列 $a_{1 \cdots n}$,每次你可以交换相邻的两个数,如果你可以在 $\frac{n \cdot(n-1)}{2}-1$ 次内使得数列有序(单调不减),输出 `YES`,否则输出 `NO`。 - **多组数据** , 保证 $1 \leq t \leq 1000 , \sum ^{t}_{i=1}n \leq 10^5 , n \le 5 \cdot 10^4,1 \leq a_i \leq 10^9$。 - by 226148

加入题单

上一题 下一题 算法标签: