Submission #1025954

#TimeUsernameProblemLanguageResultExecution timeMemory
1025954ttamxThe short shank; Redemption (BOI21_prison)C++17
100 / 100
201 ms53848 KiB
#include<bits/stdc++.h> using namespace std; const int INF=INT_MAX/2; const int N=2e6+5; int n,d,t,m; int a[N],pre[N],par[N]; int ans; pair<int,int> range[N]; int dep[N],deep[N],cnt[N]; stack<pair<int,int>> s,st; int main(){ cin.tie(nullptr)->sync_with_stdio(false); cin >> n >> d >> t; for(int i=1;i<=n;i++)cin >> a[i]; s.emplace(-INF,0); for(int i=1;i<=n;i++){ int x=min(a[i],t)-i; while(s.top().first>x)s.pop(); if(a[i]>t)pre[i]=s.top().second; else ans++; s.emplace(a[i]-i,i); } for(int i=1;i<=n;i++)if(pre[i])range[++m]={pre[i],i-1}; ans+=m; for(int i=1;i<=m;i++){ int x=range[i].first; while(!st.empty()&&st.top().first>=x){ par[st.top().second]=i; st.pop(); } st.emplace(x,i); } for(int u=1;u<=m;u++){ cnt[dep[deep[u]]]--; dep[u]=dep[deep[u]]+1; cnt[dep[u]]++; if(dep[u]>dep[deep[par[u]]])deep[par[u]]=u; } for(int i=m;i>=1;i--)while(cnt[i]--&&d-->0)ans-=i; cout << 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...