제출 #838626

#제출 시각아이디문제언어결과실행 시간메모리
838626winter0101The short shank; Redemption (BOI21_prison)C++17
80 / 100
2073 ms342484 KiB
#include<bits/stdc++.h> using namespace std; #define all(fl) fl.begin(),fl.end() #define pb push_back #define fi first #define se second #define for1(i,j,k) for(int i=j;i<=k;i++) #define for2(i,j,k) for(int i=j;i>=k;i--) #define for3(i,j,k,l) for(int i=j;i<=k;i+=l) #define lb lower_bound #define ub upper_bound #define sz(a) (int)a.size() #define pii pair<int,int> #define pli pair<long long,int> #define gcd __gcd #define lcm(x,y) x*y/__gcd(x,y) const int maxn=2e6+9; const int inf=1e9+7; int a[maxn]; int n,d,t1; int st[maxn*4]; int lazy[maxn*4]; int p[maxn*4]; void update(int id,int l,int r,int u,int val){ if (l>u||r<u)return; if (l==r){ st[id]=val; p[id]=l; return; } int mid=(l+r)/2; update(id*2,l,mid,u,val); update(id*2+1,mid+1,r,u,val); st[id]=min(st[id*2],st[id*2+1]); } int walk(int id,int l,int r,int val){ if (st[id]>val)return -1; if (l==r)return l; int mid=(l+r)/2; if (st[id*2+1]<=val)return walk(id*2+1,mid+1,r,val); return walk(id*2,l,mid,val); } void push(int id){ if (lazy[id]){ st[id*2]+=lazy[id]; st[id*2+1]+=lazy[id]; lazy[id*2]+=lazy[id]; lazy[id*2+1]+=lazy[id]; lazy[id]=0; } } void combine(int id){ st[id]=max(st[id*2],st[id*2+1]); if (st[id*2]>st[id*2+1]){ p[id]=p[id*2]; } else p[id]=p[id*2+1]; } void build(int id,int l,int r){ p[id]=l; st[id]=0; if (l==r)return; int mid=(l+r)/2; build(id*2,l,mid); build(id*2+1,mid+1,r); } void range_update(int id,int l,int r,int u,int v,int val){ if (l>v||r<u||u>v)return; if (u<=l&&r<=v){ st[id]+=val; lazy[id]+=val; return; } int mid=(l+r)/2; push(id); range_update(id*2,l,mid,u,v,val); range_update(id*2+1,mid+1,r,u,v,val); combine(id); } struct line{ int l,r; bool operator < (const line &p1)const { if (l==p1.l)return r<p1.r; return l<p1.l; } }; bool vis[maxn]; vector<int> save[maxn*4]; vector<line>t; void addline(int id,int l,int r,int u,int v,int dd){ if (l>v||r<u||u>v)return ; if (u<=l&&r<=v){ save[id].pb(dd); return; } int mid=(l+r)/2; addline(id*2,l,mid,u,v,dd); addline(id*2+1,mid+1,r,u,v,dd); } //vector<int>xoaxoa; void xoa(int id,int l,int r,int u){ if (l>u||r<u)return; //cout<<id<<" "<<l<<" "<<r<<" "<<u<<'\n'; for (auto v:save[id]){ //cerr<<v<<'\n'; //cerr<<t[v].l<<" "<<t[v].r<<'\n'; if (!vis[v]){ range_update(1,1,n-1,t[v].l,t[v].r,-1); //xoaxoa.pb(v); vis[v]=1; } } vector<int>().swap(save[id]); if (l==r)return; int mid=(l+r)/2; if (mid>=u)xoa(id*2,l,mid,u); else xoa(id*2+1,mid+1,r,u); } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); //freopen("temp.INP","r",stdin); //freopen("temp.OUT","w",stdout); cin>>n>>d>>t1; for1(i,1,n)cin>>a[i]; for1(i,1,n)update(1,1,n,i,inf); int prison=0; for1(i,1,n){ int val=a[i]-i; int need=t1-i; if (val<=need){ update(1,1,n,i,val); prison++; continue; } int pos=walk(1,1,n,need); update(1,1,n,i,val); if (pos==-1)continue; prison++; t.pb({pos,i-1}); } build(1,1,n-1); for1(i,0,sz(t)-1) { auto v=t[i]; range_update(1,1,n-1,v.l,v.r,1); addline(1,1,n-1,v.l,v.r,i); } for1(i,1,d){ if (st[1]==0)break; prison-=st[1]; int pos=p[1]; xoa(1,1,n-1,pos); } cout<<prison; }
#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...