-
Notifications
You must be signed in to change notification settings - Fork 0
/
D.cpp
59 lines (57 loc) · 1.16 KB
/
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
55
56
57
58
59
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
long long ara[200005];
int main()
{
fastio;
long long t,n,i,p,l,r;
cin>>t;
while(t--)
{
cin>>n;
p=0;
l=0;
r=0;
for(i=0;i<n;i++)
cin>>ara[i];
if(n==1)
{
cout<<"YES\n";
continue;
}
for(i=0;i<n;i++)
{
if(i==0)
{
if(ara[r]<ara[r+1])
{
//cout<<l<<" "<<r<<"\n";
p++;
}
}
else
{
if(ara[i]==ara[i-1])
r++;
else
{
l=i;
r=i;
}
if((ara[l-1]>ara[l] || l==0) && (ara[r]<ara[r+1] || r==n-1))
{
//cout<<l<<" "<<r<<"\n";
p++;
}
}
}
//cout<<p<<"\n";
if(p==1)
cout<<"YES\n";
else
cout<<"NO\n";
}
return 0;
}