Submission #1130441

#TimeUsernameProblemLanguageResultExecution timeMemory
1130441VMaksimoski008Financial Report (JOI21_financial)C++17
48 / 100
4093 ms21620 KiB
#include <bits/stdc++.h> #define ar array //#define int long long using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const int mod = 1e9 + 7; const int LOG = 20; const int maxn = 1e5 + 5; struct union_find { int n; vector<int> par, size, L, R, mx; union_find(int _n) : n(_n), par(n+1), size(n+1, 1), L(n+1), R(n+1), mx(n+1, 0) { for(int i=1; i<=n; i++) par[i] = L[i] = R[i] = i; } int find(int u) { if(u == par[u]) return u; return par[u] = find(par[u]); } void uni(int a, int b) { a = find(a); b = find(b); if(a == b) return ; if(size[a] < size[b]) swap(a, b); size[a] += size[b]; par[b] = a; L[a] = min(L[a], L[b]); R[a] = max(R[a], R[b]); mx[a] = max(mx[a], mx[b]); } void set_dp(int u, int val) { mx[find(u)] = max(mx[find(u)], val); } int get_l(int u) { return L[find(u)]; } int get_r(int u) { return R[find(u)]; } int get_dp(int u) { return mx[find(u)]; } }; struct segment_tree { int n; vector<int> tree, lazy; segment_tree(int _n) : n(_n), tree(4*n), lazy(4*n) {} void push(int u, int tl, int tr) { if(!lazy[u]) return ; tree[u] = max(tree[u], lazy[u]); if(tl != tr) { lazy[2*u] = max(lazy[2*u], lazy[u]); lazy[2*u+1] = max(lazy[2*u+1], lazy[u]); } lazy[u] = 0; } void update(int u, int tl, int tr, int l, int r, int v) { push(u, tl, tr); if(tl > r || l > tr) return ; if(l <= tl && tr <= r) { lazy[u] = max(lazy[u], v); push(u, tl, tr); return ; } int tm = (tl + tr) / 2; update(2*u, tl, tm, l, r, v); update(2*u+1, tm+1, tr, l, r, v); tree[u] = max(tree[2*u], tree[2*u+1]); } int query(int u, int tl, int tr, int l, int r) { if(tl > r || l > tr) return 0; push(u, tl, tr); if(l <= tl && tr <= r) return tree[u]; int tm = (tl + tr) / 2; return max(query(2*u, tl, tm, l, r), query(2*u+1, tm+1, tr, l, r)); } void update(int l, int r, int v) { update(1, 1, n, l, r, v); } int query(int l, int r) { return query(1, 1, n, l, r); } }; signed main() { int n, d; cin >> n >> d; vector<int> dp(n+1), a(n+1); map<int, vector<int> > mp; for(int i=1; i<=n; i++) { cin >> a[i]; mp[a[i]].push_back(i); } int diff = 0; union_find dsu(n); segment_tree sgt(n); vector<int> act(n+1); for(auto [val, vec] : mp) { for(int p : vec) { dp[p] = 1; // for(int j=1; j<=n; j++) cout << dp[j] << " "; // cout << '\n'; int last = p; for(int j=p-1; j>=1; j--) { if(last - j > d) break; if(act[j]) last = j; if(a[j] != a[p]) dp[p] = max(dp[p], dp[j] + 1); } act[p] = 1; } } cout << *max_element(dp.begin(), dp.end()) << '\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...