Codeforces Round 888 (Div. 3) B题

You have an array of integers a of length n You can apply the following operation to the given array:

  • Swap two elements ai and aj such that i≠j, ai and aj are either both even or both odd.

Determine whether it is possible to sort the array in non-decreasing order by performing the operation any number of times (possibly zero).

For example, let a = [7,10,1,3,27,10,1,3,2]. Then we can perform 33 operations to sort the array:

  1. Swap a3=1and a1=7, since 11 and 77 are odd. We get a = [1,10,7,3,21,10,7,3,2];
  2. Swap a2=10 and a5=2, since 1010 and 22 are even. We get a = [1,2,7,3,101,2,7,3,10];
  3. Swap a4=3 and a3=7, since 33 and 77 are odd. We get a = [1,2,3,7,101,2,3,7,10].

Input

The first line of input data contains a single integer t (1≤t≤10的四次方) — the number of test cases.

The description of the test cases follows.

The first line of each test case contains one integer n (1≤n≤2⋅10的五次方) — the length of array a.

The second line of each test case contains exactly n positive integers a1,a2,…,an, (1≤ai≤10的九次方) — the elements of array a

It is guaranteed that the sum of n over all test cases does not exceed 2⋅1052⋅105.

Output

For each test case, output on a separate line:

  • YES if the array can be sorted by applying the operation to it some number of times;
  • NO otherwise.

You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as positive response).

Example

input

6

5

7 10 1 3 2

4

11 9 3 5

5

11 3 15 3 2

6

10 7 8 1 2 3

1

10

5

6 6 4 1 6

output

YES
YES
NO
NO
YES
NO

代码

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		int a[n],b[n];
		string ans="YES";
		for(int i=0;i<n;i++)
		cin>>a[i],b[i]=a[i];
		sort(a,a+n);
		for(int i=0;i<n;i++)
		if(a[i]%2!=b[i]%2)
		{
		   ans="NO";
		   break;	
		}
		cout<<ans<<endl;
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值