-
Notifications
You must be signed in to change notification settings - Fork 1
/
ronnies-crystal.cpp
76 lines (70 loc) · 2.07 KB
/
ronnies-crystal.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
// typedef long long int ll;
// typedef long double ld;
#define int long long int
#define f(i,j,n) for(int i = j; i <= n; i++)
#define r(i,n,j) for(int i = n; i >= j; i--)
#define mod 1000000007
#define speed ios_base::sync_with_stdio(false);
#define upp cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define T int tt; cin >> tt; while(tt--)
#define ff first
#define ss second
#define all(container) container.begin() , container.end()
#define sz(container) (int)container.size()
#define pii pair <int , int>
#define pll pair <long long int , long long int>
#define ppl pair <long long int , pll> //pair of ll and pair ll
#define sp(x) setprecision(x)
int32_t main()
{
speed upp
while(1)
{
int n;
cin>>n;
if(n==0)
break;
int a[n+1],j=1;
f(i,1,n)
cin>>a[i];
vector<int>v;
stack<int>q;
f(i,1,n)
{
if(a[i]==j)
{
v.pb(j);
j++;
continue;
}
if(!q.empty() && q.top()==j)
{
q.pop();
v.pb(j);
j++;
i--;
continue;
}
q.push(a[i]);
}
while(!q.empty())
{
v.pb(q.top());
q.pop();
}
int f=0;
f(i,1,sz(v))
if(v[i-1]!=i)
f=1;
if(f)
cout<<"no\n";
else
cout<<"yes\n";
}
}