#include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <algorithm> using namespace std; int tree[1048576][7],a[600005],n,m,A,B,C,i,ans,t,x; void Update(int x) { tree[x][2]=tree[x*2][2]+tree[x*2+1][2]; tree[x][3]=max(tree[x*2][3],tree[x*2+1][3]); tree[x][4]=max(tree[x*2][4],tree[x*2][2]+tree[x*2+1][4]); tree[x][5]=max(tree[x*2+1][5],tree[x*2+1][2]+tree[x*2][5]); tree[x][6]=max(max(tree[x*2][6],tree[x*2+1][6]),tree[x*2][5]+tree[x*2+1][4]); } int WORK(int root,int l,int r) { if (tree[root][0]==l && tree[root][1]==r) return tree[root][3]; int mid=(tree[root][0]+tree[root][1])/2,p=-2000000000,q=-2000000000; if (l<=mid) p=WORK(root*2,l,min(mid,r)); if (r>mid) q=WORK(root*2+1,max(l,mid+1),r); return max(p,q); } void work(int root,int l,int r) { if (tree[root][0]==l && tree[root][1]==r) { ans=max(ans,tree[root][4]+t); ans=max(ans,tree[root][6]); t=max(t+tree[root][2],tree[root][5]); t=max(t,0); return; } int mid=(tree[root][0]+tree[root][1])/2; if (l<=mid) work(root*2,l,min(mid,r)); if (r>mid) work(root*2+1,max(mid+1,l),r); } int main() { scanf("%d%d",&n,&m); for (i=1; i<=n; i++) scanf("%d",&a[i]); for (i=524288; i<=1048575; i++) { tree[i][0]=tree[i][1]=i; tree[i][2]=tree[i][3]=a[i-524287]; tree[i][4]=tree[i][5]=tree[i][6]=max(a[i-524287],0); } for (i=524287; i>=1; i--) { tree[i][0]=tree[i*2][0]; tree[i][1]=tree[i*2+1][1]; Update(i); } for (i=1; i<=m; i++) { scanf("%d%d%d",&A,&B,&C); if (A==2) { x=524287+B; tree[x][2]=tree[x][3]=C; tree[x][4]=tree[x][5]=tree[x][6]=max(C,0); while (x!=1) { x/=2; Update(x); } } else { if (B>C) swap(B,C); t=0; ans=WORK(1,B+524287,C+524287); if (ans<0) printf("%d ",ans); else { work(1,B+524287,C+524287); printf("%d ",ans); } } } return 0; }