Open neal2018 opened 2 years ago
monotonic
function<void(int, int, int, int)> dfs = [&](int l, int r, int poss_l, int poss_r) {
if (l >= r) return;
int mid = (l + r) / 2;
int best = poss_l;
for (int i = poss_l; i < poss_r; i++) {
ll cur = cost(mid, i);
if (cur > dp[mid]) dp[mid] = cur, best = i;
}
dfs(l, mid, poss_l, best + 1);
dfs(mid + 1, r, best, poss_r);
};
dfs(0, n, 0, n);
convex hull trick / slope trick
https://codeforces.com/contest/1715/submission/169121067