欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1670A.Prof. Slim
Prof. Slim
One day Prof. Slim decided to leave the kingdom of the GUC to join the kingdom of the GIU. He was given an easy online assessment to solve before joining the GIU. Citizens of the GUC were happy sad to see the prof leaving, so they decided to hack into the system and change the online assessment into a harder one so that he stays at the GUC. After a long argument, they decided to change it into the following problem.
Given an array of integers , where , check if you can make this array sorted by using the following operation any number of times (possibly zero). An array is sorted if its elements are arranged in a non-decreasing order.
- select two indices and () such that and have different signs. In other words, one must be positive and one must be negative.
- swap the signs of and . For example if you select and , then they will change to and .
Prof. Slim saw that the problem is still too easy and isn't worth his time, so he decided to give it to you to solve.
Input
The first line contains a single integer () — the number of test cases. Then test cases follow.
The first line of each test case contains a single integer () — the length of the array .
The next line contain integers (, ) separated by spaces describing elements of the array .
It is guaranteed that the sum of over all test cases doesn't exceed .
Output
For each test case, print "YES" if the array can be sorted in the non-decreasing order, otherwise print "NO". You can print each letter in any case (upper or lower).
Note
In the first test case, there is no way to make the array sorted using the operation any number of times.
In the second test case, the array is already sorted.
In the third test case, we can swap the sign of the -st element with the sign of the -th element, and the sign of the -rd element with the sign of the -th element, this way the array will be sorted.
In the fourth test case, there is no way to make the array sorted using the operation any number of times.
Samples
4
7
7 3 2 -11 -13 -17 -23
6
4 10 25 47 71 96
6
71 -35 7 -4 -11 -25
6
-45 9 -48 -67 -55 7
NO
YES
YES
NO
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |