#pragma GCC optimize(3)
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 500010;
int n, m;
int a[N];
struct T{
int l, r;
int sum, premax, sufmax, tmax;
}tr[N * 4];
inline void pushup(int u) {
tr[u].sum = tr[u << 1].sum + tr[u << 1 | 1].sum;
tr[u].premax = max(tr[u << 1].premax, tr[u << 1].sum + tr[u << 1 | 1].premax);
tr[u].sufmax = max(tr[u << 1 | 1].sufmax, tr[u << 1 | 1].sum + tr[u << 1].sufmax);
tr[u].tmax = max({tr[u << 1].sufmax + tr[u << 1 | 1].premax, tr[u << 1].tmax, tr[u << 1 | 1].tmax});
}
void build(int u, int l, int r) {
tr[u] = {l, r, a[l], a[l], a[l], a[l]};
if(l == r) return;
int mid = tr[u].l + tr[u].r >> 1;
build(u << 1, l, mid), build(u << 1 | 1, mid + 1, r);
pushup(u);
}
void modify(int u, int k, int v) {
if(tr[u].l == tr[u].r) {
tr[u] = {k, k, v, v, v, v};
return;
}
int mid = tr[u].l + tr[u].r >> 1;
if(k <= mid) modify(u << 1, k, v);
else modify(u << 1 | 1, k, v);
pushup(u);
}
T query(int u, int l, int r) {
if(l <= tr[u].l && tr[u].r <= r) return tr[u];
int mid = tr[u].l + tr[u].r >> 1;
if(r <= mid) return query(u << 1, l, r);
if(l > mid) return query(u << 1 | 1, l, r);
T lson = query(u << 1, l, r);
T rson = query(u << 1 | 1, l, r);
T ans;
ans.sum = lson.sum + rson.sum;
ans.premax = max(lson.premax, lson.sum + rson.premax);
ans.sufmax = max(rson.sufmax, rson.sum + lson.sufmax);
ans.tmax = max({lson.tmax, rson.tmax, lson.sufmax + rson.premax});
return ans;
}
int main() {
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
build(1, 1, n);
while(m--) {
int t, x ,y;
scanf("%d%d%d", &t, &x, &y);
if(t == 1) {
if (x > y) swap(x, y);
printf("%d\n", query(1, x, y).tmax);
}
else modify(1, x, y);
}
return 0;
}