Submission #886136

#TimeUsernameProblemLanguageResultExecution timeMemory
886136imarnFinancial Report (JOI21_financial)C++14
19 / 100
752 ms27980 KiB
#include "bits/stdc++.h" #define f first #define s second #define ll long long #define pb push_back #define pii pair<ll,ll> #define all(x) x.begin(),x.end() using namespace std; const int N=3e5+5; struct lazy{ ll t[4*N]{0},lz[4*N]{0}; void push(int i,int l,int r){ if(lz[i]){ t[i]=lz[i]; if(l<r){ lz[2*i]=lz[i]; lz[2*i+1]=lz[i]; }lz[i]=0; } } void upd(int i,int l,int r,int tl,int tr,int v){ push(i,l,r); if(r<tl||l>tr)return; if(r<=tr&&l>=tl){ lz[i]=v;push(i,l,r);return; }int m=(l+r)>>1; upd(2*i,l,m,tl,tr,v);upd(2*i+1,m+1,r,tl,tr,v); t[i]=t[2*i]+t[2*i+1]; } ll qr(int i,int l,int r,int idx){ push(i,l,r); if(r<idx||l>idx)return 0; if(l==r)return t[i]; int m=(l+r)>>1; return max(qr(2*i,l,m,idx),qr(2*i+1,m+1,r,idx)); } }lt; ll t[2*N]{0}; void upd1(int i,ll amt,int sz){ i+=sz;t[i]=amt; for(i>>=1;i;i>>=1)t[i]=max(t[2*i],t[2*i+1]); } void upd2(int i,ll amt,int sz){ i+=sz;t[i]=max(amt,t[i]); for(i>>=1;i;i>>=1)t[i]=max(t[2*i],t[2*i+1]); } ll qr(int l,int r,int sz,ll res=0){ for(l+=sz,r+=sz;l<r;l>>=1,r>>=1){ if(l&1)res=max(res,t[l++]); if(r&1)res=max(res,t[--r]); }return res; } vector<ll>co; int main(){ ios_base::sync_with_stdio(0);cin.tie(0); ll n,d;cin>>n>>d; ll a[n+1];int ans=0; for(int i=1;i<=n;i++)cin>>a[i],co.pb(a[i]); sort(all(co));co.erase(unique(all(co)),co.end());int sz=co.size(); for(int i=1;i<=n;i++){ int id = upper_bound(all(co),a[i])-co.begin(); int l=1,r=sz; while(l<r){ int m=(l+r)>>1; if(i-lt.qr(1,1,sz,m)>d)l=m+1; else r=m; } int tmp = qr(l-1,id-1,sz)+1;ans=max(ans,tmp); if(l<=id)upd2(id-1,tmp,sz); else upd1(id-1,tmp,sz); lt.upd(1,1,sz,id,sz,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...