aish @ 2023-11-23 14:31:15
问题可能有 3:
left-most, right-most, answer
设为了 max(0, v)
(当然,这样应该过不了样例例如这是正确的:
Node query(int L, int R, int p = 1, int l = 1, int r = n) {
if (L <= l && r <= R) return val[p];
int mid = (l + r) >> 1;
if (R <= mid) return query(L, R, lc(p), l, mid);
if (L > mid) return query(L, R, rc(p), mid + 1, r);
return query(L, R, lc(p), l, mid) + query(L, R, rc(p), mid + 1, r);
}
但是这是错误的:
Node query(int L, int R, int p = 1, int l = 1, int r = n) {
if (L <= l && r <= R) return val[p];
int mid = (l + r) >> 1;
Node res = {0, 0, 0, -inf};
if (L <= mid) res = query(L, R, lc(p), l, mid);
if (R > mid) res = res + query(L, R, rc(p), mid + 1, r);
return res;
}
附注:
struct Node {
int sum, lmo, rmo, res;
Node operator + (const Node &n) const {
return {
sum + n.sum,
max(lmo, sum + n.lmo),
max(n.rmo, n.sum + rmo),
max(max(res, n.res), rmo + n.lmo)
};
}
void init(int v) {
sum = res = lmo = rmo = v;
}
} val[N << 2];
by jianganxu @ 2024-01-22 10:37:40
改为{0,-inf,-inf,-inf}
可过