-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLEPERMUT.cpp
51 lines (46 loc) · 961 Bytes
/
LEPERMUT.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
#include <bits/stdc++.h>
#define int long long int
#define MP make_pair
#define PB push_back
#define rep(i, a, b) for (int i=a; i<b; i++)
#define endl "\n"
using namespace std;
int getInvCount(int arr[], int n)
{
int inv_count = 0;
for (int i = 0; i < n - 1; i++)
for (int j = i + 1; j < n; j++)
if (arr[i] > arr[j])
inv_count++;
return inv_count;
}
int getlocalinv(int arr[] , int n)
{
int inv = 0 ;
rep(i,0,n-1)
{
if(arr[i]>arr[i+1])
inv+=1 ;
}
return inv ;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// your code goes here
int t , n ;
cin>>t ;
while(t--)
{
cin>>n ;
int arr[n+1] ;
rep(i,0,n)
cin>>arr[i] ;
if(getInvCount(arr,n) == getlocalinv(arr,n))
cout<<"YES"<<endl ;
else
cout<<"NO"<<endl ;
}
return 0;
}