Submission #558383

#TimeUsernameProblemLanguageResultExecution timeMemory
558383Koosha_mvThe short shank; Redemption (BOI21_prison)C++14
100 / 100
1471 ms89184 KiB
#include <bits/stdc++.h> using namespace std; #define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl #define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl #define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl #define eror(x) cout<<#x<<'='<<(x)<<endl #define f_(i,a,b) for(int i=a;i>=b;i--) #define f(i,a,b) for(int i=a;i<b;i++) #define nb(x) __builtin_popcount(x) #define all(v) v.begin(),v.end() #define bit(n,k) (((n)>>(k))&1) #define Add(x,y) x=(x+y)%mod #define maxm(a,b) a=max(a,b) #define minm(a,b) a=min(a,b) #define lst(x) x[x.size()-1] #define sz(x) int(x.size()) #define mp make_pair #define ll long long #define pb push_back #define S second #define F first const int N=4e6+99; int n,d,t,ans,a[N],b[N],ps[N],L[N],R[N],ok[N]; int seg1[N<<2],seg2[N<<2],dp[N<<2]; void add(int L,int R,int val,int id=1,int l=1,int r=n+1){ if(r<=L || R<=l) return ; if(L<=l && r<=R){ seg1[id]+=val; dp[id]=seg1[id]+max(dp[id<<1],dp[id<<1|1]); return ; } int mid=(l+r)>>1; add(L,R,val,id<<1,l,mid); add(L,R,val,id<<1|1,mid,r); dp[id]=seg1[id]+max(dp[id<<1],dp[id<<1|1]); } void build(int id=1,int l=1,int r=n+1){ if(l+1==r){ seg2[id]=(ok[l] ? L[l] : N); return ; } int mid=(l+r)>>1; build(id<<1,l,mid); build(id<<1|1,mid,r); seg2[id]=min(seg2[id<<1],seg2[id<<1|1]); } int get(int id=1,int l=1,int r=n+1){ int mid=(l+r)>>1; if(l+1==r) return l; if(dp[id<<1]>=dp[id<<1|1]) return get(id<<1,l,mid); return get(id<<1|1,mid,r); } void prt(int x,int id=1,int l=1,int r=n+1){ if(r<=x || x<seg2[id]) return ; if(l+1==r){ seg2[id]=N; add(L[l],R[l],-1); return ; } int mid=(l+r)>>1; prt(x,id<<1,l,mid); prt(x,id<<1|1,mid,r); seg2[id]=min(seg2[id<<1],seg2[id<<1|1]); } int32_t main(){ ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0); vector<int> vec(1); b[0]=N; cin>>n>>d>>t; t++; minm(d,n-1); f(i,1,n+1) cin>>a[i]; f(i,1,n+1){ ok[i]=1; if(a[i]<t){ L[i]=R[i]=i; b[i]=min(n,i+t-a[i]-1); while(b[vec.back()]<=b[i]) vec.pop_back(); vec.pb(i); continue ; } ok[i]=1; while(b[vec.back()]<i) vec.pop_back(); L[i]=vec.back()+1; R[i]=i+1; if(L[i]==1) ans++,ok[i]=0; else add(L[i],R[i],1); } build(); f(i,0,d){ ans+=dp[1]; int x=get(); prt(x); } cout<<n-ans; }
#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...