Submission #1179514

#TimeUsernameProblemLanguageResultExecution timeMemory
1179514gyg송신탑 (IOI22_towers)C++20
11 / 100
4069 ms3304 KiB
#include "towers.h" #include <bits/stdc++.h> using namespace std; #define arr array #define vec vector const int N = 1e5 + 5; int n; arr<int, N> h; void init(int _n, vec<int> _h) { n = _n; for (int i = 1; i <= n; i++) h[i] = _h[i - 1]; } int s, f, d; struct Sgt { arr<int, 4 * N> tr; void intl() { tr.fill(0); } void upd(int i, int x) { tr[i] = x; } int qry(int l, int r) { int ans = 0; for (int i = l; i <= r; i++) ans = max(ans, tr[i]); return ans; } } sgt; arr<int, N> lf, rg; void prp_cmp() { sgt.intl(); for (int i = 1; i <= n; i++) sgt.upd(i, h[i]); for (int i = 1; i <= n; i++) { int lw = 1, hg = i; while (lw < hg) { int md = (lw + hg + 1) / 2; if (sgt.qry(md, i) >= h[i] + d) lw = md; else hg = md - 1; } lf[i] = (sgt.qry(lw, i) >= h[i] + d) ? lw : 1; lw = i, hg = n; while (lw < hg) { int md = (lw + hg) / 2; if (sgt.qry(i, md) >= h[i] + d) hg = md; else lw = md + 1; } rg[i] = (sgt.qry(i, lw) >= h[i] + d) ? lw : n; } // for (int i = 1; i <= n; i++) { // cout << i << ": " << lf[i] << " " << rg[i] << '\n'; // } } arr<int, N> dp; void dp_cmp() { for (int i = s; i <= f; i++) { dp[i] = 1; for (int j = s; j <= i - 1; j++) { if (j < lf[i] && i > rg[j]) { dp[i] = max(dp[i], dp[j] + 1); } } } } int max_towers(int _s, int _f, int _d) { s = _s + 1, f = _f + 1, d = _d; prp_cmp(); dp_cmp(); int ans = 0; for (int i = s; i <= f; i++) ans = max(ans, dp[i]); return ans; }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...