-
Notifications
You must be signed in to change notification settings - Fork 332
/
Copy pathLarry's_Array.cpp
40 lines (36 loc) · 885 Bytes
/
Larry's_Array.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
/*
* 1) A rotation does not change the parity of the number of inversions.
* 2) If the array is sortable, then the initial number of inversions is even.
* 3) If the initial number of inversions is even, then the array is sortable.
*/
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int t;
cin>>t;
for(int i=0;i<t;i++){
int n;
cin>>n;
vector<int>v(n);
for(int j=0;j<n;j++)
cin>>v[j];
int swaps=0;
for(int i=0;i<v.size();i++){
for(int j=0;j<v.size()-1;j++){
if(v[j]>v[j+1]){
swap(v[j],v[j+1]);
swaps++;
}
}
}
if(swaps%2==0)
cout<<"YES"<<endl;
else
cout<<"NO\n";
}
return 0;
}