Submission #738366

#TimeUsernameProblemLanguageResultExecution timeMemory
738366alexddFinancial Report (JOI21_financial)C++17
48 / 100
4081 ms10396 KiB
#include<bits/stdc++.h> using namespace std; int n,d; int a[300005]; int pozs[300005]; int dp[300005]; void calc_pozs() { for(int i=1;i<=n;i++) { int ult=i; pozs[i]=i; for(int j=i-1;j>0;j--) { if(ult-j>d) break; if(a[j]<a[i]) { ult=j; pozs[i]=j; } } } } pair<int,int> ord2[300005]; int aint[1210000]; void upd(int nod, int st, int dr, int poz, int newv) { if(st==dr) { aint[nod]=newv; return; } int mij=(st+dr)/2; if(poz<=mij) upd(nod*2,st,mij,poz,newv); else upd(nod*2+1,mij+1,dr,poz,newv); aint[nod]=max(aint[nod*2],aint[nod*2+1]); } int qry(int nod, int st, int dr, int le, int ri) { if(le>ri) return 0; if(le==st && dr==ri) return aint[nod]; int mij=(st+dr)/2; return max(qry(nod*2,st,mij,le,min(mij,ri)), qry(nod*2+1,mij+1,dr,max(mij+1,le),ri)); } signed main() { ios_base::sync_with_stdio(0);cin.tie(0); cin>>n>>d; for(int i=1;i<=n;i++) cin>>a[i]; calc_pozs(); for(int i=1;i<=n;i++) { ord2[i]={a[i],-i}; } sort(ord2+1,ord2+1+n); int cur; for(int i=1;i<=n;i++) { cur = -ord2[i].second; dp[cur] = qry(1,1,n,pozs[cur],cur-1) + 1; upd(1,1,n,cur,dp[cur]); } int rez=1; for(int i=1;i<=n;i++) rez=max(rez,dp[i]); cout<<rez; 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...