wdl_ @ 2023-08-02 11:17:10
#include<bits/stdc++.h>
#define int long long
#define INT_MIN LLONG_MIN
using namespace std;
int n,m,tree[5000005],a[1000005],op,a1,a2,a3,lazytag1[5000005],lazytag2[2000005];
void pushup(int k)
{
tree[k] = max(tree[k * 2],tree[k * 2 + 1]);
lazytag2[k] = INT_MIN;
}
void add1(int k,int v)
{
lazytag1[k] += v;
tree[k] += lazytag1[k];
}
void add2(int k,int v)
{
lazytag2[k] = v;
tree[k] = lazytag2[k];
}
void pushdown2(int k)
{
if(lazytag2[k] == INT_MIN)return;
lazytag1[k] = 0;
add2(k * 2,lazytag2[k]);
add2(k * 2 + 1,lazytag2[k]);
lazytag2[k] = INT_MIN;
}
void pushdown1(int k)
{
pushdown2(k);
if(lazytag1[k] == 0)return;
add1(k * 2,lazytag1[k]);
add1(k * 2 + 1,lazytag1[k]);
lazytag1[k] = 0;
}
void build(int k,int l,int r)
{
if(l == r)
{
tree[k] = a[l];
return;
}
int mid = (l + r) >> 1;
build(k * 2,l,mid);
build(k * 2 + 1,mid + 1,r);
pushup(k);
}
void update1(int k,int l,int r,int x,int y,int v)
{
if(l > y || r < x)return;
if(l >= x && r <= y)
{
//lazytag2[k] = 1e9 + 1;
pushdown2(k);
lazytag1[k] += v;
tree[k] += v;
return;
}
int mid = (l + r) >> 1;
pushdown1(k);
update1(k * 2,l,mid,x,y,v);
update1(k * 2 + 1,mid + 1,r,x,y,v);
pushup(k);
}
void update2(int k,int l,int r,int x,int y,int v)
{
if(l > y || r < x)return;
if(l >= x && r <= y)
{
lazytag1[k] = 0;
lazytag2[k] = v;
tree[k] = v;
return;
}
int mid = (l + r) >> 1;
pushdown2(k);
update2(k * 2,l,mid,x,y,v);
update2(k * 2 + 1,mid + 1,r,x,y,v);
pushup(k);
}
int ask(int k,int l,int r,int x,int y)
{
if(l > y || r < x)return INT_MIN;
if(l >= x && r <= y)return tree[k];
int mid = (l + r) >> 1;
pushdown1(k);
//pushdown2(k);
return max(ask(k * 2,l,mid,x,y),ask(k * 2 + 1,mid + 1,r,x,y));
}
signed main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
cin >> n >> m;
for(int i = 1;i <= n;i ++)cin >> a[i];
build(1,1,n);
for(int i = 1;i <= m;i ++)
{
cin >> op;
if(op == 1)
{
cin >> a1 >> a2 >> a3;
update2(1,1,n,a1,a2,a3);
}
if(op == 2)
{
cin >> a1 >> a2 >> a3;
update1(1,1,n,a1,a2,a3);
}
if(op == 3)
{
cin >> a1 >> a2;
cout << ask(1,1,n,a1,a2) << endl;
}
}
return 0;
}