제출 #1136290

#제출 시각아이디문제언어결과실행 시간메모리
1136290onlk97Financial Report (JOI21_financial)C++20
100 / 100
704 ms59104 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>; 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]; map <int,vector <int> > mp; for (int i=1; i<=n; i++) mp[a[i]].pb(i); Seg seg; seg.init(n); set <int> bad; for (int i=1; i<=n-d+1; i++) bad.insert(i); for (auto i:mp){ vector <pii> vec; int prv=0; for (int j:i.y){ auto it=bad.lower_bound(j-d+1); int idx; if (it==bad.begin()) idx=1; else idx=(*(--it))+d; int ths=seg.query(1,1,n,idx,j-1)+1; seg.update(1,1,n,j,ths-1); while (1){ auto it=bad.lower_bound(j-d+1); if (it==bad.end()||(*it)>j) break; bad.erase(it); } } for (int j:i.y) seg.update(1,1,n,j,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...