Submission #465595

#TimeUsernameProblemLanguageResultExecution timeMemory
465595mariowongFinancial Report (JOI21_financial)C++14
19 / 100
317 ms12032 KiB
#include <bits/stdc++.h> using namespace std; int n,d,ct,a[300005],seg[1200005],ans,now; deque <int> dq; vector <pair<int,int> > v; void update(int id,int l,int r,int pos,int v){ if (l == r) seg[id]=v; else { int mid=(l+r)/2; if (pos <= mid) update(id*2,l,mid,pos,v); else update(id*2+1,mid+1,r,pos,v); seg[id]=max(seg[id*2],seg[id*2+1]); } } int query(int id,int l,int r,int x,int y){ if (x <= l && y >= r) return seg[id]; if (l > y || r < x) return -1; int mid=(l+r)/2; return max(query(id*2,l,mid,x,y),query(id*2+1,mid+1,r,x,y)); } int main(){ ios::sync_with_stdio(false); cin.tie(0); cin >> n >> d; for (int i=1;i<=n;i++){ cin >> a[i]; v.push_back(make_pair(a[i],i)); } sort(v.begin(),v.end()); for (int i=0;i<n;i++){ if (i == 0 || v[i].first != v[i-1].first) ct++; a[v[i].second]=ct; } for (int i=1;i<=n;i++){ if (!dq.empty() && i-dq.front() > d){ update(1,0,ct,a[dq.front()],0); dq.pop_front(); } now=max(query(1,0,ct,a[i],a[i]),query(1,0,ct,0,a[i]-1)+1); update(1,0,ct,a[i],now); ans=max(ans,now); while (!dq.empty() && a[dq.back()] >= a[i]){ dq.pop_back(); } dq.push_back(i); } cout << ans << "\n"; 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...