Submission #738393

#TimeUsernameProblemLanguageResultExecution timeMemory
738393alexddFinancial Report (JOI21_financial)C++17
100 / 100
399 ms17548 KiB
#include<bits/stdc++.h> using namespace std; int n,d; int a[300005]; int pozs[300005]; int dp[300005]; pair<int,int> ord[300005]; set<pair<int,int>> secv; void calc_pozs() { for(int i=1;i<=n;i++) { ord[i]={a[i],-i}; } sort(ord+1,ord+1+n); int cur; secv.insert({1,n}); set<pair<int,int>>::iterator it; pair<int,int> cop; for(int i=1;i<=n;i++) { cur=-ord[i].second; if(!secv.empty()) { it=secv.upper_bound({cur+1,cur}); it--; cop=*it; //cout<<cur<<" "<<cop.first<<" "<<cop.second<<"\n"; if(cop.first <= cur && cur <= cop.second) { secv.erase(it); if(cur-cop.first >= d) secv.insert({cop.first, cur-1}); if(cop.second-cur >= d) secv.insert({cur+1,cop.second}); } } it=secv.lower_bound({cur+1,cur}); if(!secv.empty() && it!=secv.begin()) { it--; cop=*it; pozs[cur]=cop.second+1; } else pozs[cur]=1; //pozs[cur]=min(pozs[cur],cur); //cout<<cur<<" "<<pozs[cur]<<"\n"; } } 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...