【参考代码】
#include<bits/stdc++.h>
using namespace std;
stack<int>st1;
int a[1001];
int main()
{
int n,j=1;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
for(int i=1;i<=n;i++)
{
st1.push(i);
while(!st1.empty()&&a[j]==st1.top())
{
st1.pop();
j++;
}
}
if(st1.empty())
{
cout<<"YES";
}
else
{
cout<<"NO";
}
return 0;
}