欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1420A.Cubes Sorting
Cubes Sorting
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 cubes. -th cube has a volume .
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 , must hold.
To achieve his goal, Wheatley can exchange two neighbouring cubes. It means that for any you can exchange cubes on positions and .
But there is a problem: Wheatley is very impatient. If Wheatley needs more than exchange operations, he won't do this boring work.
Wheatly wants to know: can cubes be sorted under this conditions?
Input
Each test contains multiple test cases.
The first line contains one positive integer (), denoting the number of test cases. Description of the test cases follows.
The first line of each test case contains one positive integer () — number of cubes.
The second line contains positive integers () — volumes of cubes.
It is guaranteed that the sum of over all test cases does not exceed .
Output
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.
Note
In the first test case it is possible to sort all the cubes in exchanges.
In the second test case the cubes are already sorted.
In the third test case we can make exchanges, but the cubes are not sorted yet, so the answer is "NO".
Samples
3
5
5 3 2 1 4
6
2 2 2 2 2 2
2
2 1
YES
YES
NO
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |