제출 #1109277

#제출 시각아이디문제언어결과실행 시간메모리
1109277SalihSahinFinancial Report (JOI21_financial)C++14
19 / 100
248 ms33360 KiB
#include <bits/stdc++.h> #define pb push_back #define int long long using namespace std; const int mod = 998244353; const int inf = 1e9 + 20; const int N = 1e5+5; struct SEGTMX{ vector<int> tree; void init(int n){ tree.assign(4*n, 0); } void update(int ind, int l, int r, int pos, int val){ if(l == r){ tree[ind] = val; } else{ int m = (l + r)/2; if(pos <= m) update(ind*2, l, m, pos, val); else update(ind*2+1, m+1, r, pos, val); tree[ind] = max(tree[ind*2], tree[ind*2+1]); } } int query(int ind, int l, int r, int ql, int qr){ if(l > r || l > qr || r < ql) return 0; if(l >= ql && r <= qr) return tree[ind]; else{ int m = (l + r)/2; return max(query(ind*2, l, m, ql, qr), query(ind*2+1, m+1, r, ql, qr)); } } }; int32_t main(){ cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); int n, d; cin>>n>>d; vector<int> a(n); vector<pair<int, int> > b(n); for(int i = 0; i < n; i++){ cin>>a[i]; b[i] = {a[i], -i}; } sort(b.begin(), b.end()); SEGTMX seg; seg.init(n); vector<int> nxt(n); for(int i = 0; i < n; i++){ int ind = -b[i].second; nxt[ind] = seg.query(1, 1, n, ind + 1, min(n, ind + d + 1)); if(nxt[ind] == 0) nxt[ind] = min(ind + d, n-1); seg.update(1, 1, n, ind + 1, nxt[ind]); } vector<int> lp(n); int ind = n-1; for(int i = n-1; i >= 0; i--){ while(ind >= 0 && nxt[ind] >= i) ind--; lp[i] = ind + 1; } SEGTMX segmx; segmx.init(n); vector<int> dp(n); for(int i = 0; i < n; i++){ int ind = -b[i].second; int l = lp[ind] + 1, r = ind + 1; int val = segmx.query(1, 1, n, l, r); dp[ind] = val + 1; segmx.update(1, 1, n, ind + 1, val + 1); } int ans = 0; for(int i = 0; i < n; i++){ ans = max(ans, dp[i]); } cout<<ans<<endl; 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...