#include<bits/stdc++.h> usingnamespace std; int a[200005], b[200005]; intmain() { int _, i, n; scanf("%d", &_); while (_--) { scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%d", &a[i]); b[i] = a[i]; } sort(a + 1, a + 1 + n); int ar = n & 1;//剩余元素个数是/否为奇数 for (i = 1; i <= n; i++, ar ^= 1) { //由分析可得出,可等效认为需要当前元素在a的后缀中最小,且当数组长度为偶数时,第一个元素与第二个元素可交换 if (!ar && b[i] > b[i + 1]) swap(b[i], b[i + 1]); int t = lower_bound(a + 1, a + 1 + n, b[i]) - a; if (t > i) break; } if (i <= n) printf("NO\n"); else printf("YES\n"); } return0; }