_Ventus_ @ 2023-08-10 16:06:35
#include <stdio.h>
#define int long long
const int N = 1e6 + 10;
int n, m;
struct node { int maxn, tg, tg1 = 1e18; } 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 PushDown1(int l, int r, int u) {
if (l == r || !t[u].tg) return;
t[ls(u)].tg += t[u].tg; t[rs(u)].tg += t[u].tg;
int m = l + r >> 1;
t[ls(u)].maxn += t[u].tg; t[rs(u)].maxn += t[u].tg;
t[u].tg = 0;
}
void PushDown(int l, int r, int u) {
if (l == r || t[u].tg1 == 1e18) return;
t[ls(u)].tg = t[rs(u)].tg = t[u].tg = 0;
int m = l + r >> 1;
t[ls(u)].maxn = t[u].tg1; t[rs(u)].maxn = t[u].tg1;
t[u].tg1 = 1e18;
}
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(l, r, 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(l, r, 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(l, r, u);
PushDown1(l, r, u);
int maxn = 0, 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;
}
本地测了#6没有问题