Prolystic @ 2024-06-21 10:37:20
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 5;
const ll nval = LONG_LONG_MAX;
ll n, q, t[N << 2], tag1[N << 2], tag2[N << 2], a[N << 2];
inline ll read(ll& x){
int s = 0, w = 1;
char ch = getchar();
while(ch < '0' || ch > '9') { w = (ch == '-' ? -1 : w); ch = getchar(); }
while(ch >= '0' && ch <= '9') { s = s * 10 + ch - '0'; ch = getchar(); }
x = s * w;
}
inline void write(ll x){
if(x < 0) { putchar('-'), x = -x; }
if(x > 9) write(x / 10);
putchar(x % 10 + '0');
}
inline void write(ll x, char ch) { write(x), putchar(ch); }
inline ll ls(ll p) { return p << 1; }
inline ll rs(ll p) { return p << 1 | 1; }
inline void push_up(ll p) { t[p] = max(t[ls(p)], t[rs(p)]); }
inline void build(ll p, ll l, ll r){
if(l == r){
t[p] = a[l], tag1[p] = nval;
return;
}
ll mid = l + r >> 1;
build(ls(p), l, mid), build(rs(p), mid + 1, r);
push_up(p), tag1[p] = nval;
}
inline void cover(ll p, ll k){
t[p] = k, tag1[p] = k;
tag2[p] = 0;
}
inline void cover_down(ll p){
if(tag1[p] == nval)
return;
cover(ls(p), tag1[p]), cover(rs(p), tag1[p]);
tag1[p] = nval;
}
inline void add(ll p, ll k) { t[p] += k, tag2[p] += k; }
inline void add_down(ll p){
add(ls(p), tag2[p]), add(rs(p), tag2[p]);
tag2[p] = 0;
}
inline void push_down(ll p) { cover_down(p), add_down(p); }
inline void modify_c(ll p, ll l, ll r, ll x, ll y, ll k){
if(x <= l && r <= y){
cover(p, k);
return;
}
ll mid = l + r >> 1;
push_down(p);
if(x <= mid)
modify_c(ls(p), l, mid, x, y, k);
if(y > mid)
modify_c(rs(p), mid + 1, r, x, y, k);
push_up(p);
}
inline void modify_a(ll p, ll l, ll r, ll x, ll y, ll k){
if(x <= l && r <= y){
cover_down(p), add(p, k);
return;
}
ll mid = l + r >> 1;
push_down(p);
if(x <= mid)
modify_a(ls(p), l, mid, x, y, k);
if(y > mid)
modify_a(rs(p), mid + 1, r, x, y, k);
push_up(p);
}
inline ll query(ll p, ll l, ll r, ll x, ll y){
ll ans = LONG_LONG_MIN;
if(x <= l && r <= y)
return t[p];
ll mid = l + r >> 1;
push_down(p);
if(x <= mid)
ans = max(ans, query(ls(p), l, mid, x, y));
if(y > mid)
ans = max(ans, query(rs(p), mid + 1, r, x, y));
return ans;
}
int main(){
read(n), read(q);
for(int i = 1; i <= n; i++)
read(a[i]);
build(1, 1, n);
while(q--){
ll op, x, y, k;
read(op);
if(op == 1){
read(x), read(y), read(k);
modify_c(1, 1, n, x, y, k);
}else if(op == 2){
read(x), read(y), read(k);
modify_a(1, 1, n, x, y, k);
}else if(op == 3){
read(x), read(y);
write(query(1, 1, n, x, y), '\n');
}
}
return 0;
}
by xhz123456789 @ 2024-06-21 12:25:46
@Prolystic 第7行的read返回值为ll但你并没有return,你可以试试不使用o2,改为void,或把第12行改为“ return x = s * w; ”
by Prolystic @ 2024-06-21 13:09:07
@xhz123456789 OK,我去试试
by Prolystic @ 2024-06-21 13:11:25
@xhz123456789 现在前面的
by Prolystic @ 2024-06-21 13:15:08
@xhz123456789 我把第 64 行的 cover(p, k)
给删掉它就过了,想请教一下大佬这是为什么呢