Submission #1136280

#TimeUsernameProblemLanguageResultExecution timeMemory
1136280onlk97Financial Report (JOI21_financial)C++20
5 / 100
147 ms16868 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> #define int long long #define double long double #define x first #define y second #define pb push_back using namespace std; using namespace __gnu_pbds; using pii=pair <int,int>; using tii=pair <pii,int>; bool cmp(pii u,pii v){ if (u.x!=v.x) return u.x<v.x; return u.y>v.y; } struct Seg{ vector <int> seg; void init(int n){ seg.resize(4*n+10); } void update(int id,int tl,int tr,int pos,int val){ if (tl==tr){ seg[id]=val; return; } int tm=(tl+tr)/2; if (pos<=tm) update(2*id,tl,tm,pos,val); else update(2*id+1,tm+1,tr,pos,val); seg[id]=max(seg[2*id],seg[2*id+1]); } int query(int id,int tl,int tr,int l,int r){ if (l>r) return 0; if (l<=tl&&tr<=r) return seg[id]; int tm=(tl+tr)/2; int lx=query(2*id,tl,tm,l,min(r,tm)); int rx=query(2*id+1,tm+1,tr,max(l,tm+1),r); return max(lx,rx); } }; void solve(){ int n,d; cin>>n>>d; int a[n+1]; for (int i=1; i<=n; i++) cin>>a[i]; pii p[n+1]; for (int i=1; i<=n; i++) p[i]={a[i],i}; sort(p+1,p+n+1,cmp); Seg seg; seg.init(n); for (int i=1; i<=n; i++){ int ths=seg.query(1,1,n,max(1LL,p[i].y-d),p[i].y-1); seg.update(1,1,n,p[i].y,ths+1); } cout<<seg.query(1,1,n,1,n)<<'\n'; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); int t=1; //cin>>t; while (t--) solve(); }
#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...