제출 #1106272

#제출 시각아이디문제언어결과실행 시간메모리
1106272alexddThe short shank; Redemption (BOI21_prison)C++17
70 / 100
2072 ms46416 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int INF = 1e18; int n,d,lim; int t[2000005]; bool blocat[2000005]; int tole[2000005]; pair<int,int> aint[4200000]; int lazy[4200000]; void build(int nod, int st, int dr) { if(st==dr) { aint[nod] = {0,st}; return; } int mij=(st+dr)/2; build(nod*2,st,mij); build(nod*2+1,mij+1,dr); aint[nod] = max(aint[nod*2], aint[nod*2+1]); } void propagate(int nod) { lazy[nod*2] += lazy[nod]; lazy[nod*2+1] += lazy[nod]; aint[nod*2].first += lazy[nod]; aint[nod*2+1].first += lazy[nod]; lazy[nod]=0; } void upd(int nod, int st, int dr, int le, int ri, int newv) { if(le>ri) return; if(le==st && dr==ri) { aint[nod].first += newv; lazy[nod] += newv; return; } propagate(nod); int mij=(st+dr)/2; upd(nod*2,st,mij,le,min(mij,ri),newv); upd(nod*2+1,mij+1,dr,max(mij+1,le),ri,newv); aint[nod] = max(aint[nod*2], aint[nod*2+1]); } signed main() { ios_base::sync_with_stdio(0);cin.tie(0); cin>>n>>d>>lim; build(1,1,n); for(int i=1;i<=n;i++) { cin>>t[i]; tole[i] = n+1; for(int j=i;j>0;j--) { if(t[j] + (i-j) <= lim) { tole[i] = j; break; } } upd(1,1,n,tole[i],i,+1); } for(int pas=1;pas<=d;pas++) { /*int mxm=0,unde=-1; for(int i=1;i<=n;i++) { int cnt=0; for(int j=i+1;j<=n;j++) if(tole[j]<=i) cnt++; if(cnt>mxm) { mxm = cnt; unde = i; } } if(unde==-1) break;*/ int unde = aint[1].second; blocat[unde]=1; for(int i=unde+1;i<=n;i++) { if(tole[i]<=unde) { upd(1,1,n,tole[i],i,-1); tole[i] = n+1; } } } int rez=0; int mnm=INF; for(int i=1;i<=n;i++) { if(blocat[i-1]) mnm=INF; mnm = min(mnm, t[i]-i); if(mnm <= lim-i) rez++; } cout<<rez; return 0; } /* pentru fiecare pozitie i ne intereseaza doar cea mai din dreapta pozitie j aflata in stanga ei care respecta j <= i t[j] + (i-j) <= lim t[j] - j <= lim - i */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...