奇偶排列:
一个排列中,如果交换两个数,那么它排列的奇偶性一定发生变化。
参考:百度-奇排列-性质1
(1)考虑数组中的数两两不相同:比较当前数组与不下降数组之间排列奇偶性。如果它们排列的奇偶性相同,可以变化,否则不行。具体请自行证明。
(2)数组中有相同的数:数组逆序对奇偶性可以随意转换,就一定能转换为不下降子序列。
逆序对树:acwing板子
// Problem: D. Yet Another Sorting Problem
// Contest: Codeforces - Codeforces Round #759 (Div. 2, based on Technocup 2022 Elimination Round 3)
// URL: https://codeforces.com/contest/1591/problem/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define lowbit(x) (x&-x)
#define pf(a) printf("%d\n",a)
#define mem(x,y) memset(x,y,sizeof(x))
#define dbg(x) cout << #x << " = " << x << endl
#define rep(i,l,r) for(int i = l; i <= r; i++)
#define fep(i,a,b) for(int i=b; i>=a; --i)
#define PII pair<int,int>
typedef long long ll;
const int N = 1e6+10;
int n,m;
int a[N], b[N];
ll cnt;
void merge_sort(int a[], int l, int r)
{
if(l>=r) return;
int mid = (l+r)>>1;
merge_sort(a,l,mid);
merge_sort(a,mid+1,r);
int i = l, j = mid + 1;
for(int k = l; k <= r; k++) {
if(j>r || (i<=mid && a[i]<=a[j])) b[k] = a[i++];
else cnt += mid - i + 1, b[k] = a[j++];
}
for(int k = l; k <= r; k++) a[k] = b[k];
}
void solve()
{
cnt=0;
scanf("%d",&n);
rep(i,1,n) {
scanf("%d",&a[i]);
b[i] = a[i];
}
sort(b+1,b+1+n);
rep(i,1,n){
if(b[i-1]==b[i]) {
puts("YES");
return;
}
}
merge_sort(a,1,n);
puts(cnt&1?"NO":"YES");
}
int main()
{
int t;
scanf("%d", &t);
while(t--)
solve();
return 0;
}