#include #include #include #include using namespace std; using ll = long long; template using vec = vector; template using vvec = vector>; template class SegmentTree{ private: using F = function; int sz; vector seg; const F op;//演算 const Monoid e;//単位元 public: SegmentTree(int n,const F op,const Monoid &e):op(op),e(e){ sz = 1; while(sz0;i--){ seg[i] = op(seg[2*i],seg[2*i+1]); } } void update(int k,const Monoid &x){ k += sz; seg[k] += x; while(k>>=1){ seg[k] = op(seg[2*k],seg[2*k+1]); } } Monoid query(int l,int r){ Monoid L = e,R = e; for(l+=sz,r+=sz;l>=1,r>>=1){ if(l&1) L = op(L,seg[l++]); if(r&1) R = op(seg[--r],R); } return op(L,R); } Monoid operator[](const int &k)const{ return seg[k+sz]; } }; int main(){ int N; cin >> N; vec P(N),Q(N); for(int i=0;i> P[i]; P[i]--; Q[P[i]] = i; } SegmentTree seg(N+1,[](int a,int b){return max(a,b);},-1); int l = 0; for(int i=0;i ans; for(int i=N-1;i>=0;i--){ int ma = seg.query(Q[i]+1,N); if(ma==-1){ for(int j=Q[i]-1;j>=0;j--) if(P[j]!=-1) ans.push_back(P[j]); break; }else{ if(Q[i]==l){ cout << "No" << endl; return 0; } ans.push_back(i); seg.update(Q[i],-1); P[Q[i]] = -1; while(Q[l]==-1) l++; } } cout << "Yes" << endl; for(int i=0;i