-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD.cpp
54 lines (51 loc) · 989 Bytes
/
D.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <bits/stdc++.h>
using namespace std;
#define cerr cerr << "DEBUG "
int solve(vector<int> &a, int l, int r) {
if (r - l <= 1) {
return 0;
}
int m = (r + l) >> 1;
int ret = solve(a, l, m) ^ solve(a, m, r);
vector<int> tmp;
int pl = l, pr = m;
while (pl != m || pr != r) {
int ll = pl == m ? INT_MAX : a[pl];
int rr = pr == r ? INT_MAX : a[pr];
if (ll < rr) {
tmp.push_back(ll);
++pl;
} else {
tmp.push_back(rr);
ret ^= (m - pl) & 1;
++pr;
}
}
for (int j = 0; j < r - l; ++j) {
a[j + l] = tmp[j];
}
return ret;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int tc;
cin >> tc;
while (tc--) {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
if (set<int>(a.begin(), a.end()).size() != a.size()) {
cout << "YES\n";
continue;
}
if (solve(a, 0, n)) {
cout << "NO\n";
} else {
cout << "YES\n";
}
}
}