CF1670A Prof. Slim

题目描述

给定一个由$n$个整数$a_1, a_2, \ldots, a_n (a_{i} \neq 0)$构成的数组,问是否能通过任意次下面的操作将该数组排成一个非递减序列。 操作: 选定两个异号(一正一负)的数$a_i, a_j(1\leq i, j\leq n)$,交换$a_{i}$和$ a_{j}$的符号。例如当$a_i=3,a_j=-2$时, 进行该操作后$a_i=-3, a_j=2$。

输入格式

第一行为一个整数$t ( 1 \le t \le 10^4)$,共$t$组数据。 每组数据的第一行为一个整数$n( 1 \le n \le 10^{5})$,第二行为$n$个整数$a_1, a_2, \ldots, a_n( -10^9 \le a_{i} \le 10^9, a_{i} \neq 0)$。 数据保证所有测试案例中$n$的和不超过$10^5$。

输出格式

对每组数据,如果可行,输出"YES",否则输出"NO"。(不区分大小写)

说明/提示

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.