제출 #1025948

#제출 시각아이디문제언어결과실행 시간메모리
1025948ttamxThe short shank; Redemption (BOI21_prison)C++17
100 / 100
286 ms156388 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]; vector<int> g[N]; int dep[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=0;i<n;i++)cin >> a[i]; s.emplace(-INF,-1); for(int i=0;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 pre[i]=-1,ans++; s.emplace(a[i]-i,i); } for(int i=0;i<n;i++)if(pre[i]!=-1)range[m++]={pre[i],i-1}; ans+=m; for(int i=0;i<m;i++){ par[i]=-1; int x=range[i].first; while(!st.empty()&&st.top().first>=x){ int j=st.top().second; st.pop(); g[i].emplace_back(j); par[j]=i; } st.emplace(x,i); } for(int u=0;u<m;u++){ int deep=-1; for(auto v:g[u])if(dep[v]>dep[u])dep[u]=dep[v],deep=v; for(auto v:g[u])if(v!=deep)cnt[dep[v]]++; dep[u]++; if(par[u]==-1)cnt[dep[u]]++; } for(int i=m;i>=0;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...