Submission #533155

#TimeUsernameProblemLanguageResultExecution timeMemory
5331554fectaFinancial Report (JOI21_financial)C++17
19 / 100
896 ms42664 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define int ll #define ld long double #define pii pair<int, int> #define f first #define s second #define boost() cin.tie(0), cin.sync_with_stdio(0) #define mid ((l + r) / 2) struct node { int dp, dead, i, lzy; }; const int MN = 300005; int n, d, a[MN], ans = 1, pos[MN]; vector<pii> v; node st[4 * MN]; node push_up(node p, node q) { node ret{}; ret.dp = max(p.dp, q.dp); if (p.dead < q.dead) ret.dead = p.dead, ret.i = p.i; else ret.dead = q.dead, ret.i = q.i; return ret; } void push_down(int l, int r, int idx) { if (!st[idx].lzy) return; st[idx].dead = max(st[idx].dead, st[idx].lzy); if (l != r) st[idx * 2].lzy = max(st[idx * 2].lzy, st[idx].lzy), st[idx * 2 + 1].lzy = max(st[idx * 2 + 1].lzy, st[idx].lzy); st[idx].lzy = 0; } void build(int l, int r, int idx) { if (l == r) {st[idx] = {-0x3f3f3f3f, 0x3f3f3f3f, l, 0}; return;} build(l, mid, idx * 2), build(mid + 1, r, idx * 2 + 1); st[idx] = push_up(st[idx * 2], st[idx * 2 + 1]); } void set_dp(int l, int r, int x, int val, int idx) { push_down(l, r, idx); if (l == r) {st[idx].dp = val; return;} if (x <= mid) set_dp(l, mid, x, val, idx * 2); else set_dp(mid + 1, r, x, val, idx * 2 + 1); st[idx] = push_up(st[idx * 2], st[idx * 2 + 1]); } void set_dead(int l, int r, int x, int val, int idx) { push_down(l, r, idx); if (l == r) {st[idx].dead = val; return;} if (x <= mid) set_dead(l, mid, x, val, idx * 2); else set_dead(mid + 1, r, x, val, idx * 2 + 1); st[idx] = push_up(st[idx * 2], st[idx * 2 + 1]); } void chmax(int l, int r, int x, int y, int val, int idx) { push_down(l, r, idx); if (r < x || l > y) return; if (r <= y && l >= x) { st[idx].lzy = val; push_down(l, r, idx); return; } chmax(l, mid, x, y, val, idx * 2), chmax(mid + 1, r, x, y, val, idx * 2 + 1); st[idx] = push_up(st[idx * 2], st[idx * 2 + 1]); } int qry(int l, int r, int x, int y, int idx) { push_down(l, r, idx); if (r < x || l > y) return -0x3f3f3f3f; if (r <= y && l >= x) return st[idx].dp; return max(qry(l, mid, x, y, idx * 2), qry(mid + 1, r, x, y, idx * 2 + 1)); } bool cmp(pii p, pii q) { if (p.f != q.f) return p.f < q.f; return p.s > q.s; } int32_t main() { boost(); cin >> n >> d; for (int i = 1; i <= n; i++) cin >> a[i], v.push_back({a[i], i}); sort(v.begin(), v.end(), cmp); for (int i = 0; i < n; i++) pos[v[i].s] = i + 1; build(1, n, 1); for (int i = 1; i <= n; i++) { while (st[1].dead < i - d) { int j = st[1].i; set_dp(1, n, j, -0x3f3f3f3f, 1); set_dead(1, n, j, 0x3f3f3f3f, 1); } int tmp = max(0ll, qry(1, n, 1, pos[i], 1)) + 1; set_dead(1, n, pos[i], i, 1); chmax(1, n, pos[i], n, i, 1); ans = max(ans, tmp); set_dp(1, n, pos[i], tmp, 1); } printf("%lld\n", ans); 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...