Submission #501582

#TimeUsernameProblemLanguageResultExecution timeMemory
501582amunduzbaevFinancial Report (JOI21_financial)C++14
100 / 100
751 ms55228 KiB
#include "bits/stdc++.h" using namespace std; #define ar array #define int long long const int N = 3e5 + 5; struct ST{ int tree[N * 4], p[N * 4]; void push(int x, int lx, int rx){ if(lx == rx || !p[x]) return; tree[x<<1] = tree[x<<1|1] = tree[x]; p[x<<1] = p[x<<1|1] = 1; p[x] = 0; } void sett(int l, int r, int v, int lx = 0, int rx = N, int x = 1){ if(lx > r || rx < l) return; if(lx >= l && rx <= r){ tree[x] = v; p[x] = 1; return; } push(x, lx, rx); int m = (lx + rx) >> 1; sett(l, r, v, lx, m, x<<1), sett(l, r, v, m+1, rx, x<<1|1); tree[x] = max(tree[x<<1], tree[x<<1|1]); } int get(int l, int r, int lx = 0, int rx = N, int x = 1){ if(lx > r || rx < l) return -2e9; if(lx >= l && rx <= r) return tree[x]; push(x, lx, rx); int m = (lx + rx) >> 1; return max(get(l, r, lx, m, x<<1), get(l, r, m+1, rx, x<<1|1)); } }tree, dp; signed main(){ ios::sync_with_stdio(0); cin.tie(0); int n, d; cin>>n>>d; vector<int> a(n + 1); map<int, int> mm; for(int i=1;i<=n;i++) cin>>a[i], mm[a[i]]; int cnt = 1; for(auto& x : mm) x.second = cnt++; for(int i=1;i<=n;i++) a[i] = mm[a[i]]; for(int i=1;i<=n;i++) tree.sett(i, i, -a[i]); for(int i=1;i<=n;i++){ dp.sett(a[i], a[i], max(dp.get(a[i], a[i]), dp.get(0, a[i] - 1) + 1)); dp.sett(0, -tree.get(max(1ll, i - d + 1), i) - 1, 0); } cout<<dp.get(0, n)<<"\n"; }
#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...