_Ventus_ @ 2023-08-11 13:21:00
#include <stdio.h>
#define int long long
const int N = 1e6 + 10, INF = 1e18;
int n, m;
struct node { int maxn = -INF, tg, tg1 = -INF; } t[N << 2];
inline int ls(int u) { return u << 1; }
inline int rs(int u) { return u << 1 | 1; }
inline int max(int x, int y) { return x > y ? x : y; }
inline void PushUp(int u) { t[u].maxn = max(t[ls(u)].maxn, t[rs(u)].maxn); }
void PushDown(int u) {
if (t[u].tg1 == -INF) return;
t[ls(u)].maxn = t[u].tg1; t[rs(u)].maxn = t[u].tg1;
t[u].tg1 = -INF;
}
void PushDown1(int u) {
if (!t[u].tg) return;
PushDown(u);
t[ls(u)].tg += t[u].tg; t[rs(u)].tg += t[u].tg;
t[ls(u)].maxn += t[u].tg; t[rs(u)].maxn += t[u].tg;
t[u].tg = 0;
}
void Build(int l, int r, int u) {
if (l == r) { scanf("%lld", &t[u].maxn); return; }
int m = l + r >> 1;
Build(l, m, ls(u)); Build(m + 1, r, rs(u));
PushUp(u);
}
void Update1(int L, int R, int x, int l, int r, int u) {
if (L <= l && r <= R) { t[u].maxn += x; t[u].tg += x; return; }
PushDown1(u);
int m = l + r >> 1;
if (L <= m) Update1(L, R, x, l, m, ls(u));
if (m < R) Update1(L, R, x, m + 1, r, rs(u));
PushUp(u);
}
void Update(int L, int R, int x, int l, int r, int u) {
if (L <= l && r <= R) { t[u].maxn = x; t[u].tg1 = x; return; }
PushDown(u);
int m = l + r >> 1;
if (L <= m) Update(L, R, x, l, m, ls(u));
if (m < R) Update(L, R, x, m + 1, r, rs(u));
PushUp(u);
}
int Query(int L, int R, int l, int r, int u) {
if (L <= l && r <= R) return t[u].maxn;
PushDown(u); PushDown1(u);
int maxn = -INF, m = l + r >> 1;
if (L <= m) maxn = max(maxn, Query(L, R, l, m, ls(u)));
if (m < R) maxn = max(maxn, Query(L, R, m + 1, r, rs(u)));
return maxn;
}
signed main() {
scanf("%lld%lld", &n, &m);
Build(1, n, 1);
while (m--) {
int op, l, r;
scanf("%lld%lld%lld", &op, &l, &r);
if (op == 1) { int x; scanf("%lld", &x); Update(l, r, x, 1, n, 1); }
else if (op == 2) { int x; scanf("%lld", &x); Update1(l, r, x, 1, n, 1); }
else printf("%lld\n", Query(l, r, 1, n, 1));
}
return 0;
}
by ryf_loser @ 2023-08-11 13:25:32
@Ventus 你确定
struct node { int maxn = -INF, tg, tg1 = -INF; } t[N << 2];
可以吗
by _Ventus_ @ 2023-08-11 13:31:34
@ryf20100124 有什么问题吗
by ryf_loser @ 2023-08-11 13:32:38
@Ventus 我没这么写过……
感觉有亿点奇怪。
by _Ventus_ @ 2023-08-11 13:34:16
@ryf20100124 关键是还有60pts