Submission #666183

#TimeUsernameProblemLanguageResultExecution timeMemory
666183uroskThe short shank; Redemption (BOI21_prison)C++14
0 / 100
112 ms82596 KiB
#define here cerr<<"===========================================\n" #define dbg(x) cerr<<#x<<": "<<x<<endl; #include <bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> #define ld double #define ll long long #define llinf 100000000000000000LL // 10^17 #define pb push_back #define popb pop_back #define fi first #define sc second #define endl '\n' #define pll pair<ll,ll> #define pld pair<ld,ld> #define sz(a) (ll)(a.size()) #define all(a) a.begin(),a.end() #define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;} #define cer(a) {cerr<<#a<<": ";for(ll x_ : a) cerr<<x_<< " ";cerr<<endl;} #define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0); using namespace std; using namespace __gnu_pbds; #define maxn 2000005 ll n,d,t,ans; ll a[maxn],p[maxn],b[maxn]; vector<ll> g[maxn]; bool vis[maxn],bio[maxn]; ll dub[maxn],maxi[maxn]; ll dfs(ll u){ ll x = u; vis[u] = 1; for(ll s : g[u]){ if(vis[s]) continue; dub[s] = dub[u] + 1; ll y = dfs(s); if(dub[y]>dub[x]) x = y; } return maxi[u] = x; } bool cmp(ll x,ll y){ return dub[x]>dub[y]; } ll c[maxn]; void tc(){ cin >> n >> d >> t; for(ll i = 1;i<=n;i++) cin >> a[i]; stack<ll> s; ll rmax = 0,r = 0; for(ll i = 1;i<=n;i++){ if(a[i]>t){ b[i] = rmax; rmax = 0; while(sz(s)&&b[i]<i){ p[s.top()] = i; b[i] = max(b[i],b[s.top()]); s.pop(); } s.push(i); }else rmax = max(rmax,i+t-a[i]); c[i] = r; r = max(r,rmax); } while(sz(s)){ if(c[s.top()]>=s.top()) p[s.top()] = s.top(); s.pop(); } for(ll i = 1;i<=n;i++) if(a[i]>t) g[p[i]].pb(i); priority_queue<pll> pq; ans = n; for(ll i = n;i>=1;i--){ if(a[i]<=t) continue; if(vis[i]) continue; if(sz(g[i])==0&&c[i]<i){ans--;continue;} dub[i] = 1; ll x = dfs(i); pq.push({dub[x],x}); } while(sz(pq)&&d){ ll u = pq.top().sc; ll dept = pq.top().fi; ans-=dept; pq.pop(); while(1){ bio[u] = 1; for(ll s : g[u]){ if(!bio[s]) pq.push({dub[maxi[s]]-dub[u],maxi[s]}); } if(bio[p[u]]) break; if(u==p[u]) break; u = p[u]; } d--; } cout<<ans<<endl; } int main(){ daj_mi_malo_vremena int t; t = 1; while(t--){ tc(); } return 0; }
#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...