#include <bits/stdc++.h>
using namespace std;
#define int long long
inline int $() {
int x = 0, f = 0; char c = 0;
while (!isdigit(c)) f |= c == '-', c = getchar();
while (isdigit(c)) x = (x << 3) + (x << 1) + (c & 15), c = getchar();
return f ? -x : x;
}
#define N 200010
#define INF (1e16)
int n, m, a[N];
struct node {
int a[2][2];
node (int x = -INF, int y = -INF, int z = -INF, int w = -INF) {
a[0][0] = x, a[0][1] = y, a[1][0] = z, a[1][1] = w;
}
};
node F(node x, node y) {
node r;
for (int i = 0; i <= 1; i ++) {
for (int j = 0; j <= 1; j ++) {
for (int k = 0; k <= 1; k ++) {
r.a[i][j] = max(r.a[i][j], x.a[i][k] + y.a[k][j]);
}
}
}
return r;
}
#define lid (id << 1)
#define rid (id << 1 | 1)
#define mid (l + r >> 1)
struct Seg { node s; int x, y; }tr[N * 4];
void build(int id, int l, int r) {
if (l == r) {
return tr[id].s = node(0, -a[l], a[l], 0), void();
}
build(lid, l, mid), build(rid, mid + 1, r);
tr[id].s = F(tr[lid].s, tr[rid].s);
}
void Calc(int id, int l, int r) {
int x = tr[id].x, y = tr[id].y;
if (y < 0) {
tr[id].s = node(0ll, -(x + (r - l) * y), x, -y * (r - l));
} else {
tr[id].s = node(y * (r - l), -x, y * (r - l) + x, 0ll);
}
}
void Down(int id, int l, int r) {
if (l == r) return;
if (tr[id].x == 0 && tr[id].y == 0) return;
tr[lid].x = tr[id].x;
tr[rid].x = tr[id].x + tr[id].y * (mid - l + 1);
tr[lid].y = tr[rid].y = tr[id].y;
tr[id].x = tr[id].y = 0;
Calc(lid, l, mid), Calc(rid, mid + 1, r);
}
void Add(int id, int l, int r, int L, int R, int x, int y) {
Down(id, l, r);
if (L <= l && r <= R) {
return tr[id].x = x, tr[id].y = y, Calc(id, l, r);
}
if (L <= mid) Add(lid, l, mid, L, R, x, y);
if (R > mid) Add(rid, mid + 1, r, L, R, x + max(0ll, mid - max(l, L) + 1) * y, y);
tr[id].s = F(tr[lid].s, tr[rid].s);
}
node Ask(int id, int l, int r, int L, int R) {
Down(id, l, r);
if (L <= l && r <= R) return tr[id].s;
node lr, rr; int vl = 0, vr = 0;
if (L <= mid) lr = Ask(lid, l, mid, L, R), vl = 1;
if (R > mid) rr = Ask(rid, mid + 1, r, L, R), vr = 1;
if (!vl) return rr;
if (!vr) return lr;
return F(lr, rr);
}
signed main() {
freopen("gem.in", "r", stdin);
freopen("gem.out", "w", stdout);
n = $(), m = $();
for (int i = 1; i <= n; i ++) a[i] = $();
build(1, 1, n);
for (int i = 1; i <= m; i ++) {
int op = $(), l = $(), r = $(), x, y;
if (op == 1) {
printf("%lld\n", Ask(1, 1, n, l, r).a[0][0]);
} else {
x = $(), y = $(), Add(1, 1, n, l, r, x, y);
}
}
return 0;
}