// library begin: "lib/template.hpp" #ifdef TEMPLATE #else #define TEMPLATE # pragma GCC optimize("O3") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; namespace ryoku{} using uint=unsigned; using ll=long long; using ull=unsigned long long; using ld=long double; using pii=pair; using pll=pair; using i128=__int128; using u128=unsigned __int128; templateusing vc=vector; templateusing vvc=vc>; templateusing vvvc=vvc>; templateusing smpq=priority_queue,greater>; templateusing bipq=priority_queue; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) #define REP(i,j,n) for(ll i=(j);i<(ll)(n);i++) #define DREP(i,n,m) for(ll i=(n);i>=(m);i--) #define drep(i,n) for(ll i=((n)-1);i>=0;i--) #define rall(x) x.rbegin(),x.rend() #define mp(...) make_pair(__VA_ARGS__) #define pb push_back #define fi first #define se second #define is insert #define bg begin() #define ed end() #define all(x) x.begin(),x.end() void scan(int&a) { cin >> a; } void scan(ll&a) { cin >> a; } void scan(string&a) { cin >> a; } void scan(char&a) { cin >> a; } void scan(uint&a) { cin >> a; } void scan(ull&a) { cin >> a; } void scan(bool&a) { cin >> a; } void scan(ld&a){ cin>> a;} template void scan(vector&a) { for(auto&x:a) scan(x); } void read() {} template void read(Head&head, Tail&... tail) { scan(head); read(tail...); } #define INT(...) int __VA_ARGS__; read(__VA_ARGS__); #define LL(...) ll __VA_ARGS__; read(__VA_ARGS__); #define ULL(...) ull __VA_ARGS__; read(__VA_ARGS__); #define STR(...) string __VA_ARGS__; read(__VA_ARGS__); #define VC(type, name, ...) vector name(__VA_ARGS__); read(name); #define VVC(type, name, size, ...) vector> name(size, vector(__VA_ARGS__)); read(name); templatevoid print(T a) { cout << a; } template void print(vectora) { for(int i=0;i<(int)a.size();i++){if(i)cout<<" ";print(a[i]);}} void PRT() { cout < void PRT(T a) { print(a); cout < void PRT(Head head, Tail ... tail) { print(head); cout << " "; PRT(tail...); return; } template bool chmin(T &x, F y){ if(x>y){ x=y; return true; } return false; } template bool chmax(T &x, F y){ if(x T floor(T a,T b){ return a/b-(a%b&&((a<0)!=(b<0))); } template T ceil(T a,T b){ return a/b+(a%b&&((a<0)==(b<0))); } template T bmod(T x,T y){ return x-y*floor(x,y); } template pairdivmod(T x,T y){ T q=floor(x,y); return{q,x-q*y}; } void YesNo(bool b){ cout<<(b?"Yes":"No")<stovi(const string&s,const string&S){ vcv(s.size()); rep(i,s.size()){ auto t=S.find(s[i]); assert(t!=string::npos); v[i]=t; } return v; } template T isqrt(T x){ T F=sqrtl(x); while((F+1)*(F+1)<=x)F++; while(F*F>x)F--; return F; } template T tri(T x){return x*(x-1)/2;} //[l,r) templateT tri(T l,T r){return (r-l)*(l+r-1)/2;} //n を先頭に持ってくる template vcrot(vcv,int n){ rotate(v.begin(),v.begin()+n,v.end()); return v; } template auto rle(const Container&cv){ using T=typename Container::value_type; vc>res; for(const auto&x:cv){ if(res.empty()||res.back().fi!=x)res.pb({x,1}); else res.back().se++; } return res; } template vciota(int n){ vcv(n);rep(i,n)v[i]=i; return v; } template vcargsort(const vc&a){ auto idx=iota(a.size()); sort(all(idx),[&](int i,int j){ return (minfirst?make_pair(a[i],i)make_pair(a[j],j)); }); return idx; } template vvctrans(const vvc&a){ assert(a.size()&&a[0].size()); rep(i,a.size())assert(a[i].size()==a[0].size()); vvcb(a[0].size(),vc(a.size())); rep(i,a.size())rep(j,a[0].size())b[j][i]=a[i][j]; return b; } vctrans(const vc&a){ assert(a.size()&&a[0].size()); rep(i,a.size())assert(a[i].size()==a[0].size()); vcb(a[0].size(),string(a.size(),0)); rep(i,a.size())rep(j,a[0].size())b[j][i]=a[i][j]; return b; } template int popcount(T n){ return __builtin_popcountll(n); } template L sum(const vc&a){ return accumulate(all(a),L(0)); } template struct subset_view{ T s; struct iterator{ T s,x; bool done; T operator*()const{return x;} iterator&operator++(){ if(x==0)done=true; else x=(x-1)&s; return*this; } bool operator!=(const iterator&r)const{return done!=r.done;} }; iterator begin()const{return{s,s,false};} iterator end()const{return{s,0,true};} }; template subset_viewsubset(T s){ return{s}; } template T max(vc&a){ return *max_element(all(a)); } template T min(vc&a){ return *min_element(all(a)); } template vc presum(vc &a){ vc ret(a.size()+1); rep(i,a.size())ret[i+1]=ret[i]+a[i]; return ret; } template vc &operator+=(vc &a,F b){ for (auto&v:a)v += b; return a; } template vc &operator-=(vc&a,F b){ for (auto&v:a)v-=b; return a; } template vc &operator*=(vc&a,F b){ for (auto&v:a)v*=b; return a; } template constexpr T pow(T a,T b){ T res=1; while(b){ if(b&1)res*=a; a*=a; b/=2; } return res; } constexpr ll ten(ll a){ return pow(10,a); } templateconstexpr T inf=numeric_limits::max()/2-1; template<> constexpr pll inf ={inf,inf}; template constexpr T neg_inf=-inf; template<> constexpr pll neg_inf ={-inf,-inf}; template int tbit(T x){ using U=make_unsigned_t; U y=(U)x; return y?(int)bit_width(y)-1:-1; } template int lbit(T x){ using U=make_unsigned_t; U y=(U)x; return y?(int)countr_zero(y):-1; } template int tbit(T x,int p){ using U=make_unsigned_t; constexpr int W=numeric_limits::digits; U y=(U)x; if(p<0)return -1; if(p>=W-1)return tbit(y); return tbit(y&((U(1)<<(p+1))-1)); } template int lbit(T x,int p){ using U=make_unsigned_t; constexpr int W=numeric_limits::digits; U y=(U)x; if(p<0)return lbit(y); if(p>=W)return -1; return lbit(y&(~U(0)<>(istream&is,i128&x){ string s;is>>s; x=0; int i=0,neg=0; if(s[0]=='-')neg=1,i=1; for(;i<(int)s.size();i++)x=x*10+s[i]-'0'; if(neg)x=-x; return is; } ostream& operator<<(ostream&os,i128 x){ if(x==0)return os<<0; if(x<0)os<<"-"; u128 y=x<0?-(u128)x:(u128)x; string s; while(y)s.pb('0'+y%10),y/=10; reverse(all(s)); return os<sync_with_stdio(0); #ifdef LOCAL cout< struct lazy_segtree{ using info=typename acted::info; using tag=typename acted::tag; using value_type=typename acted::value_type; using lazy_type=typename acted::lazy_type; template struct has_commute{ static constexpr bool value=false; }; template struct has_commute{ static constexpr bool value=T::commute; }; static constexpr bool commute=has_commute::value; int N; int n; int lg; vcnode; vclazy; vclen; void build(int N_){ assert(N_>=0); N=N_; lg=0; while((1<(n*2,info::id()); lazy=vc(n,tag::id()); len=vc(n*2); REP(i,n,n*2)len[i]=(i-n A){ build(N); A.resize(n,info::id()); REP(i,n,n*2)node[i]=A[i-n]; DREP(i,n-1,1)update(i); } templaterequires is_invocable_r_v lazy_segtree(int N,F f){ build(N); REP(i,n,n*2){ if(i-n>j); node[i]=x; for(int j=1;j<=lg;j++)update(i>>j); } value_type prod(int l,int r){ assert(0<=l&&l<=r&&r<=N); if(l==r)return info::id(); if constexpr(commute){ auto dfs=[&](auto&dfs,int k,int sl,int sr,lazy_type x)->value_type{ if(sr<=l||r<=sl)return info::id(); if(l<=sl&&sr<=r)return acted::act(node[k],x,len[k]); x=tag::op(lazy[k],x); int mid=(sl+sr)>>1; return info::op(dfs(dfs,k*2,sl,mid,x),dfs(dfs,k*2+1,mid,sr,x)); }; return dfs(dfs,1,0,n,tag::id()); } l+=n,r+=n; for(int i=lg;i;i--){ if(((l>>i)<>i); if(((r>>i)<>i); } value_type sml=info::id(),smr=info::id(); while(l>i)<>i); if(((r>>i)<>i); } } int l2=l,r2=r; while(l2>i)<>i); if(((r>>i)<>i); } } void applyat(int i,lazy_type x){ assert(0<=i&&i>j); all_apply(i,x); for(int j=1;j<=lg;j++)update(i>>j); } value_type all_prod(){ return node[1]; } template int max_right(int L,F f){ assert(0<=L&&L<=N); if(L>i); int l=n+L,w=1; value_type ansL=info::id(); for(;L+w<=N;l>>=1,w<<=1)if(l&1){ if(!f(info::op(ansL,node[l])))break; ansL=info::op(ansL,node[l++]); L+=w; } while(w>1){ if(0>=1; if(L+w<=N&&f(info::op(ansL,node[l]))){ ansL=info::op(ansL,node[l++]); L+=w; } } return L; } template int min_left(int R,F f){ assert(0<=R&&R<=N); if(R>0)for(int i=lg;i;i--)push((n+R-1)>>i); int r=n+R,w=1; value_type ansR=info::id(); for(;R-w>=0;r>>=1,w<<=1)if(r&1){ if(!f(info::op(node[r-1],ansR)))break; ansR=info::op(node[--r],ansR); R-=w; } while(w>1){ if(0>=1; if(R-w>=0&&f(info::op(node[r-1],ansR))){ ansR=info::op(node[r-1],ansR); R-=w; r--; } } return R; } }; } #ifdef LOCAL #include"lib/debug/formatters/ds--segment_tree--lazy-segtree.hpp" #endif // library end: "lib/ds/segment_tree/lazy-segtree.hpp" // library begin: "lib/ds/act/add.hpp" // library include: "lib/template.hpp" // library begin: "lib/ds/monoid/min-max.hpp" // library include: "lib/template.hpp" namespace ryoku{ template> struct Min{ using value_type=T; static constexpr bool commute=true; static value_type op(value_type a,value_type b){return min(a,b);} static value_type id(){return INF;} static value_type e(){return id();} }; template> struct Max{ using value_type=T; static constexpr bool commute=true; static value_type op(value_type a,value_type b){return max(a,b);} static value_type id(){return NEG_INF;} static value_type e(){return id();} }; } // library end: "lib/ds/monoid/min-max.hpp" // library begin: "lib/ds/monoid/sum-prod.hpp" // library include: "lib/template.hpp" namespace ryoku{ template struct Sum{ using value_type=T; static constexpr bool commute=true; static value_type op(value_type a,value_type b){return a+b;} static value_type id(){return T(0);} static value_type e(){return id();} }; template struct Prod{ using value_type=T; static constexpr bool commute=true; static value_type op(value_type a,value_type b){return a*b;} static value_type id(){return T(1);} static value_type e(){return id();} }; } // library end: "lib/ds/monoid/sum-prod.hpp" namespace ryoku{ template struct add_min{ using info=Min; using tag=Sum; using value_type=typename info::value_type; using lazy_type=typename tag::value_type; static value_type act(value_type x,lazy_type f,ll){return x+f;} }; template struct add_max{ using info=Max; using tag=Sum; using value_type=typename info::value_type; using lazy_type=typename tag::value_type; static value_type act(value_type x,lazy_type f,ll){return x+f;} }; template struct add_sum{ using info=Sum; using tag=Sum; using value_type=typename info::value_type; using lazy_type=typename tag::value_type; static value_type act(value_type x,lazy_type f,ll len){return x+f*len;} }; } // library end: "lib/ds/act/add.hpp" // library include: "lib/ds/segment_tree/lazy-segtree.hpp" using namespace ryoku; void solve(){ INT(n); VC(ll,a,n); lazy_segtree>seg(n); rep(i,n){ seg.set(i,i+1-a[i]); } while(1){ rep(i,n)dbg(seg.prod(i,i+1)); int r=seg.max_right(0,[&](auto a){ return a>0; }); if(r==n)break; seg.apply(0,r,-1); seg.set(r,r+1); } rep(i,n)if(seg.prod(i,i+1)!=i+1)return No(); Yes(); } signed main(){ int t=1; // cin >> t; while(t--)solve(); }