Codeforces Round 788 (Div. 2)
A
Prof. Slim
Codeforces
800
原题
←B →
翻译中…

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 $n$ integers $a_1,a_2,\ldots,a_n$, where $a_{i} \neq 0$, 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.

翻译中…
  1. select two indices $i$ and $j$ ($1 \le i,j \le n$) such that $a_i$ and $a_j$ have different signs. In other words, one must be positive and one must be negative.
  2. swap the signs of $a_{i}$ and $a_{j}$. For example if you select $a_i=3$ and $a_j=-2$, then they will change to $a_i=-3$ and $a_j=2$.
翻译中…

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 $t$ ($1 \le t \le 10^4$) — the number of test cases. Then $t$ test cases follow.

翻译中…

The first line of each test case contains a single integer $n$ ($1 \le n \le 10^{5}$) — the length of the array $a$.

翻译中…

The next line contain $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_{i} \le 10^9$, $a_{i} \neq 0$) separated by spaces describing elements of the array $a$.

翻译中…

It is guaranteed that the sum of $n$ over all test cases doesn't exceed $10^5$.

翻译中…

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 $1$-st element with the sign of the $5$-th element, and the sign of the $3$-rd element with the sign of the $6$-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.

翻译中…

样例

Input #1
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
Output #1
NO
YES
YES
NO
InputCopy OutputCopy
题目信息
题号
1670A
时间限制
1 s
内存限制
256 MB
标签
贪心
模拟
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。