我是蒟蒻
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e6+10;
int n, m;
int sum[N << 2], a[N];
int lazy[N << 2];
int p;
int l, r, x;
int b[N << 2];
int cover[N << 2];
void push_up(int pos) {
sum[pos] = max (sum[pos << 1], sum[pos << 1|1]);
}
void push_down(int pos, int l, int r) {
if(b[pos]) {
sum[pos << 1] = sum[pos << 1|1] = cover[pos];
cover[pos << 1] = cover[pos << 1|1] = cover[pos];
lazy[pos << 1] = lazy[pos << 1|1] = 0;
lazy[pos] = cover[pos] = b[pos] = 0;
b[pos << 1] = b[pos << 1|1] = 1;
}
if(lazy[pos]) {
lazy[pos << 1] += lazy[pos];
lazy[pos << 1|1] += lazy[pos];
sum[pos << 1] += lazy[pos];
sum[pos << 1|1] += lazy[pos];
lazy[pos] = 0;
}
}
void build(int pos, int l, int r) {
if (l == r) {
sum[pos] = a[l];
return;
}
int mid = l+r >> 1;
build(pos << 1, l, mid);
build(pos << 1|1, mid+1, r);
push_up(pos);
}
void add(int pos, int l, int r, int x, int y, int num) {
if (x <= l && y >= r) {
lazy[pos] += num;
sum[pos] += num;
return;
}
push_down(pos, l, r);
int mid = l+r >> 1;
if (x <= mid) {
add(pos << 1, l, mid, x, y, num);
}
if (y > mid) {
add(pos << 1|1, mid+1, r, x, y, num);
}
push_up(pos);
}
int find(int pos, int l, int r, int x, int y) {
if (x <= l && y >= r) {
return sum[pos];
}
push_down(pos, l, r);
int mid = l+r >> 1;
int ans=LLONG_MIN;
if (x <= mid) {
ans = max (ans, find(pos << 1, l, mid, x, y));
}
if (y>mid) {
ans = max (ans, find(pos << 1|1, mid+1, r, x, y));
}
return ans;
}
void update(int pos, int l, int r, int x, int y, int num) {
if (x <= l && y >= r) {
sum[pos] = num;
lazy[pos] = 0;
cover[pos] = num;
b[pos] = 1;
return;
}
push_down(pos, l, r);
int mid = l+r >> 1;
if (x <= mid) {
update (pos << 1, l, mid, x, y, num);
}
if (y>mid) {
update (pos << 1|1, mid+1, r, x, y, num);
}
push_up(pos);
}
signed main() {
cin >> n >> m;
for (int i=1; i<=n; i++) {
cin >> a[i];
}
build(1, 1, n);
while (m--) {
cin >> p;
if (p == 1) {
cin >> l >> r >> x;
update (1, 1, n, l, r, x);
}
if (p == 2) {
cin >> l >> r >> x;
add (1, 1, n, l, r, x);
}
if (p == 3) {
cin >> l >> r;
cout << find (1, 1, n, l, r) << '\n';
}
}
return 0;
}