forked from Aakash231217/Cp-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodeforces_odd_swap_sort.cpp
More file actions
47 lines (37 loc) · 857 Bytes
/
codeforces_odd_swap_sort.cpp
File metadata and controls
47 lines (37 loc) · 857 Bytes
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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
vector<ll> a(n);
for(int i=0;i<n;i++) cin>>a[i];
bool yes = true;
int l,r;
l=0;
r=n-1;
int k = 1;
while(k<=(n+1)/2){
for(int i=0;i<n-1;){
int z = a[i];
if(a[i]>a[i+1]&&(a[i]+a[i+1])&1){
a[i] = a[i+1];
a[i+1] = z;
i++;
}else if(a[i]>a[i+1]&&(a[i]+a[i+1])^1){
yes = false;
break;
}else{
i++;
}
}
k=k*2;
}
if(yes) cout<<"YES"<<"\n";
else cout<<"NO"<<"\n";
}
return 0;
}