llycdasanbing @ 2023-09-10 23:17:22
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MINLL -1e12;
const int MAXN = 1e6 + 7;
ll tree[4 * MAXN], mark_plus[4 * MAXN], num[MAXN], mark_exch[4 * MAXN];
ll n, m;
bool exchanged[4 * MAXN];
inline void read(ll& a) {
ll s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
s = s * 10 + ch - '0';
ch = getchar();
}
a = s * w;
}
void build(ll l, ll r, ll p) {
if (l == r) {
tree[p] = num[l];
return;
}
ll mid = (l + r) / 2;
build(l, mid, p * 2);
build(mid + 1, r, p * 2 + 1);
tree[p] = max(tree[p * 2], tree[p * 2 + 1]);
}
void pushdown(ll p) {
if (exchanged[p]) {
mark_exch[p * 2] = mark_exch[p];
mark_exch[p * 2 + 1] = mark_exch[p];
tree[p * 2] = mark_exch[p];
tree[p * 2 + 1] = mark_exch[p];
exchanged[p * 2] = 1;
exchanged[p * 2 + 1] = 1;
exchanged[p] = 0;
}
mark_plus[p * 2] += mark_plus[p];
mark_plus[p * 2 + 1] += mark_plus[p];
tree[p * 2] += mark_plus[p];
tree[p * 2 + 1] += mark_plus[p];;
mark_plus[p] = 0;
return;
}
void update(ll l, ll r, ll cl, ll cr, ll p, ll v) {
if (r < cl || l > cr)return;
if (cl >= l && cr <= r) {
tree[p] += v;
if (cr != cl)mark_plus[p] += v;
return;
}
ll mid = (cl + cr) / 2;
pushdown(p);
update(l, r, cl, mid, p * 2, v);
update(l, r, mid + 1, cr, p * 2 + 1, v);
tree[p] = max(tree[p * 2], tree[p * 2 + 1]);
return;
}
void clear(ll l, ll r, ll cl, ll cr, ll p, ll v) {
if (r < cl || l > cr)return;
if (cl >= l && cr <= r) {
tree[p] = v;
mark_plus[p] = 0;
mark_exch[p] = v;
exchanged[p] = 1;
return;
}
ll mid = (cl + cr) / 2;
pushdown(p);
clear(l, r, cl, mid, p * 2, v);
clear(l, r, mid + 1, cr, p * 2 + 1, v);
tree[p] = max(tree[p * 2], tree[p * 2 + 1]);
return;
}
ll get(ll l, ll r, ll cl, ll cr, ll p) {
if (r < cl || l > cr)return MINLL;
if (cl >= l && cr <= r) {
return tree[p];
}
ll mid = (cl + cr) / 2;
pushdown(p);;
return max(get(l, r, cl, mid, p * 2), get(l, r, mid + 1, cr, p * 2 + 1));
}
int main() {
freopen("P1253_7.in","r",stdin);
freopen("P1253_7ma.out","w",stdout);
cin >> n >> m;
for (ll i = 1; i <= n; i++)read(num[i]);
build(1, n, 1);
for (ll i = 1; i <= m; i++) {
ll op, l, r, x;
read(op);
read(l);
read(r);
switch (op) {
case 1:
read(x);
clear(l, r, 1, n, 1, x);
break;
case 2:
read(x);
update(l, r, 1, n, 1, x);
break;
case 3:
printf("%lld\n", get(l, r, 1, n, 1));
break;
}
}
}
/*
6 6
1 1 4 5 1 4
1 1 2 6
2 3 4 2
3 1 4
3 2 3
1 1 6 -1
3 1 6
*/
后四个点WA,估计是标记在哪里打错了,查了一晚上都没查出来,更玄学的是如果每一步都get一次下一次的有一些点就对了,求大佬帮忙看看,非常感谢