link
#include <bits/stdc++.h>
#define go continue
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fory(i,a,b) for(int i = a; i <= b; ++i)
using namespace std;
template <typename T> inline void read(T& t)
{
int f = 0, c = getchar();
t = 0;
while (!isdigit(c)) f |= c == '-', c = getchar();
while (isdigit(c)) t = t * 10 + c - 48, c = getchar();
if (f) t = -t;
}
template <typename T> void print(T x)
{
if (x < 0) x = -x, putchar('-');
if (x > 9) print(x / 10);
putchar(x % 10 + 48);
}
//--------------------------------------------
const int N = 500010;
struct node
{
int l, r;
//区间和 最大前缀 最大后缀 最大连续子段和
int sum, lmax, rmax, tmax;
};
int n, m;
int a[N];
struct _segment_tree
{
node t[N << 2];
int mp[N];
inline void help_push(node& u, node& l, node& r)
{
u.sum = l.sum + r.sum;
u.lmax = max(l.lmax, l.sum + r.lmax);
u.rmax = max(r.rmax, r.sum + l.rmax);
u.tmax = max(max(l.tmax, r.tmax), l.rmax + r.lmax);
}
inline void push_up(int root)
{
int h = root << 1;
help_push(t[root], t[h], t[h + 1]);
}
inline void build(int root, int l, int r)
{
if(l == r)
{
t[root] = {l, r, a[l], a[l], a[l], a[l]};
mp[l] = root;
}
else
{
t[root].l = l;
t[root].r = r;
int mid = (l + r) >> 1, h = root << 1;
build(h, l, mid);
build(h + 1, mid + 1, r);
push_up(root);
}
}
inline void change(int x, int y)
{
int id = mp[x];
t[id] = {x, x, y, y, y, y};
while(id >>= 1) push_up(id);
}
inline node query(int root, int l, int r)
{
if(t[root].l >= l && t[root].r <= r)
{
return t[root];
}
int mid = (t[root].l + t[root].r) >> 1;
int h = root << 1;
if(r <= mid) return query(h, l, r);
else if(l > mid) return query(h + 1, l, r);
else
{
node left = query(h, l, r);
node right = query(h + 1, l, r);
node ok;
help_push(ok, left, right);
return ok;
}
}
};
_segment_tree st;
signed main()
{
read(n),read(m);
fory(i, 1, n) read(a[i]);
st.build(1, 1, n);
while(m--)
{
int op, x, y;
read(op),read(x),read(y);
if(op == 1)
{
if(x > y) swap(x, y);
print(st.query(1, x, y).tmax);
puts("");
//cout << << "\n";
}
else
{
st.change(x, y);
//cout << st.t[st.mp[x]].sum << "debug" << endl;
}
}
return 0;
}