#include #include using namespace std; using namespace atcoder; const int inf = 1 << 30; struct S{ int ind; int min_; }; using F = int; S e(){ return S{-1, inf}; } S op(S l, S r){ if(l.min_ <= r.min_) return l; else return r; } S mapping(F l, S r){ return S({r.ind, r.min_ + l}); } F composition(F l, F r){ return l + r; } F id(){ return 0; } void solve(){ int n, a; cin >> n; vector A(n); for(int i = 0; i < n; i++){ cin >> a; A[i].ind = i; A[i].min_ = i + 1 - a; } lazy_segtree seg(A); while(1){ S tmp = seg.prod(0, n); if(tmp.min_ != 0) break; seg.apply(0, tmp.ind, -1); seg.apply(tmp.ind, tmp.ind + 1, tmp.ind + 1); } for(int i = 0; i < n; i++){ if(seg.get(i).min_ != i + 1){ cout << "No\n"; return; } } cout << "Yes\n"; } int main(){ cin.tie(0)->sync_with_stdio(0); int t; t = 1; //cin >> t; while(t--) solve(); }