This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef long long ll;
typedef pair<int, int> pii;
const int N=2e6+1e5;
int n, d, t, a[N], mx[N], nx[N], be[N], h[N];
struct seg{
int sz, sm[2*N];
void ok(){
sz=1;
while(sz<n)
sz<<=1;
}
void one(int x, int lx, int rx, int l, int r){
if(lx>=r || rx<=l)
return;
if(lx>=l && rx<=r){
sm[x]=rx-lx;
return;
}
if(sm[x]==rx-lx)
sm[2*x+1]=sm[2*x+2]=sm[x]/2;
int m=(lx+rx)/2;
one(2*x+1, lx, m, l, r);
one(2*x+2, m, rx, l, r);
sm[x]=sm[2*x+1]+sm[2*x+2];
}
int sum(int x, int lx, int rx, int l, int r){
if(lx>=r || rx<=l)
return 0;
if(lx>=l && rx<=r)
return sm[x];
if(sm[x]==rx-lx)
sm[2*x+1]=sm[2*x+2]=sm[x]/2;
int m=(lx+rx)/2;
return sum(2*x+1, lx, m, l, r)+sum(2*x+2, m, rx, l, r);
}
} A;
int main(){
cin>>n>>d>>t;
for(int i=0;i<n;++i)
cin>>a[i];
A.ok();
int ans=0;
for(int i=0;i<n;++i){
mx[i]=t-a[i]+i+1;
if(a[i]<=t){
A.one(0, 0, A.sz, i, i+1);
++ans;
}
}
for(int i=0;i<n-1;++i){
if(mx[i]>i+1 && mx[i+1]<=i+1)
h[i]=1;
}
iota(nx, nx+n, 1);
iota(be, be+n, -1);
set<pii>st;
for(int i=0;i<n-1;++i){
st.insert({h[i], i});
}
for(int i=n-1;i>d;--i){
pii z=*st.begin();
st.erase(st.begin());
ans+=z.F;
int r=nx[z.S];
int l=be[z.S];
A.one(0, 0, A.sz, z.S+1, min(mx[z.S], r+1));
be[r]=l;
if(l>=0)
nx[l]=r;
if(r!=n-1){
mx[r]=max(mx[r], mx[z.S]);
st.erase({h[r], r});
h[r]=max(0, min(nx[r], mx[r]-1)-r)-A.sum(0, 0, A.sz, r+1, min(nx[r]+1, mx[r]));
st.insert({h[r], r});
}
if(l!=-1){
st.erase({h[l], l});
h[l]=max(0, min(r, mx[l]-1)-l)-A.sum(0, 0, A.sz, l+1, min(r+1, mx[l]));
st.insert({h[l], l});
}
}
cout<<ans<<'\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |