제출 #886229

#제출 시각아이디문제언어결과실행 시간메모리
886229imarnFinancial Report (JOI21_financial)C++14
100 / 100
1097 ms20452 KiB
#include "bits/stdc++.h" #define f first #define s second #define ll int #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]=max(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; int t[4*N]{0},lz[4*N]{0}; void push(int i,int l,int r){ if(lz[i]){ t[i]=0; 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){ push(i,l,r); if(r<tl||l>tr)return; if(r<=tr&&l>=tl){ lz[i]=1;push(i,l,r);return; }int m=(l+r)>>1; upd(2*i,l,m,tl,tr);upd(2*i+1,m+1,r,tl,tr); t[i]=max(t[2*i],t[2*i+1]); } void upd1(int i,int l,int r,int idx,int v){ push(i,l,r); if(r<idx||l>idx)return; if(l==r)return void(t[i]=max(t[i],v)); int m=(l+r)>>1; upd1(2*i,l,m,idx,v);upd1(2*i+1,m+1,r,idx,v); t[i]=max(t[2*i],t[2*i+1]); } ll qr(int i,int l,int r,int tl,int tr){ push(i,l,r); if(r<tl||l>tr)return 0; if(r<=tr&&l>=tl)return t[i]; int m=(l+r)>>1; return max(qr(2*i,l,m,tl,tr),qr(2*i+1,m+1,r,tl,tr)); } 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; }upd(1,1,sz,1,l-1); int tmp = qr(1,1,sz,l,id-1)+1;ans=max(tmp,ans); upd1(1,1,sz,id,tmp); 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...