#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,q,a[114514];
struct node{
int l,r,sum,dat,lmax,rmax;
}tree[114514<<2];
void build(int p,int l,int r){
tree[p].l=l; tree[p].r=r;
if(l==r){
tree[p].dat=tree[p].sum=a[l];
tree[p].lmax=tree[p].rmax=a[l];
return ;
}
int mid=(l+r)>>1;
build(p<<1,l,mid);
build(p<<1|1,mid+1,r);
tree[p].sum=tree[p<<1].sum+tree[p<<1|1].sum;
tree[p].lmax=max(tree[p<<1].lmax,tree[p<<1].sum+tree[p<<1|1].lmax);
tree[p].rmax=max(tree[p<<1|1].rmax,tree[p<<1|1].sum+tree[p<<1].rmax);
tree[p].dat=max(max(tree[p<<1].dat,tree[p<<1|1].dat),tree[p<<1].rmax+tree[p<<1|1].lmax);
return ;
}
void change(int p,int x,int val){
if(tree[p].l==tree[p].r){
tree[p].dat=tree[p].sum=val;
tree[p].lmax=tree[p].rmax=val;
return ;
}
int mid=(tree[p].l+tree[p].r)>>1;
if(x<=mid) change(p<<1,x,val);
else change(p<<1|1,x,val);
tree[p].sum=tree[p<<1].sum+tree[p<<1|1].sum;
tree[p].lmax=max(tree[p<<1].lmax,tree[p<<1].sum+tree[p<<1|1].lmax);
tree[p].rmax=max(tree[p<<1|1].rmax,tree[p<<1|1].sum+tree[p<<1].rmax);
tree[p].dat=max(max(tree[p<<1].dat,tree[p<<1|1].dat),tree[p<<1].rmax+tree[p<<1|1].lmax);
return ;
}
int query(int p,int l,int r){
if(l<=tree[p].l&&r>=tree[p].r) return tree[p].dat;
int ans=INT_MIN,mid=(tree[p].l+tree[p].r)>>1;
if(l<=mid) ans=max(ans,query(p<<1,l,r));
if(r>mid) ans=max(ans,query(p<<1|1,l,r));
return ans;
}
signed main(){
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
build(1,1,n);
cin>>q;
while(q--){
int op;
cin>>op;
if(!op){
int x,y;
cin>>x>>y;
change(1,x,y);
}
else{
int l,r;
cin>>l>>r;
cout<<query(1,l,r)<<endl;
}
}
return 0;
}