我是蒟蒻
样例还有前6个点都是可以过的,但是不知道为什么后面过不了了
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 10000005;
ll ans;
ll n, q, k;
ll a[MAXN];
ll tree[4 * MAXN];
ll lz[4 * MAXN];
bool cover[4 * MAXN];
void pushdown(int p, int s, int t) {
if (cover[p]) {
int mid = (s + t) / 2;
tree[2 * p] = tree[p];
tree[2 * p + 1] = tree[p];
lz[2 * p] = 0;
lz[2 * p + 1] = 0;
cover[2 * p] = true;
cover[2 * p + 1] = true;
cover[p] = false;
}
if (lz[p] != 0) {
int mid = (s + t) / 2;
tree[2 * p] += lz[p];
tree[2 * p + 1] += lz[p];
lz[2 * p] += lz[p];
lz[2 * p + 1] += lz[p];
lz[p] = 0;
}
}
void build(int s, int t, int p) {
if (s == t) {
tree[p] = a[s];
return;
}
int mid = (s + t) / 2;
build(s, mid, 2 * p);
build(mid + 1, t, 2 * p + 1);
tree[p] = max(tree[2 * p], tree[2 * p + 1]);
}
void change(int l, int r, ll x, int s, int t, int p) {
if (l <= s && r >= t) {
tree[p] = x;
lz[p] = 0;
cover[p] = true;
return;
}
pushdown(p, s, t);
int mid = (s + t) / 2;
if (l <= mid) change(l, r, x, s, mid, 2 * p);
if (r > mid) change(l, r, x, mid + 1, t, 2 * p + 1);
tree[p] = max(tree[2 * p], tree[2 * p + 1]);
}
void update(int l, int r, ll k, int s, int t, int p) {
if (l <= s && r >= t) {
tree[p] += k;
lz[p] += k;
return;
}
pushdown(p, s, t);
int mid = (s + t) / 2;
if (l <= mid) update(l, r, k, s, mid, 2 * p);
if (r > mid) update(l, r, k, mid + 1, t, 2 * p + 1);
tree[p] = max(tree[2 * p], tree[2 * p + 1]);
}
ll query(int l, int r, int s, int t, int p) {
if (l <= s && r >= t) {
return tree[p];
}
pushdown(p, s, t);
int mid = (s + t) / 2;
if (l <= mid) ans = max(ans, query(l, r, s, mid, 2 * p));
if (r > mid) ans = max(ans, query(l, r, mid + 1, t, 2 * p + 1));
return ans;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>q;
for(int i=1;i<=n;i++){
cin>>a[i];
}
build(1,n,1);
for(int i=1;i<=q;i++){
int op=0;
cin>>op;
if(op==1){
int l,r,x=0;
cin>>l>>r>>x;
change(l,r,x,1,n,1);
}
if(op==2){
int l,r;
cin>>l>>r>>k;
update(l,r,k,1,n,1);
}
if(op==3){
int l,r=0;
cin>>l>>r;
ans = LLONG_MIN;
ans=query(l,r,1,n,1);
cout<<ans<<endl;
}
}
return 0;
}