/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Tree
{
long left;
long right;
long sum;
long max;
public Tree()
{
this.
left=this.
right=this.
sum=this.
max=Integer.
MIN_VALUE; }
public Tree(long val)
{
this.left=this.right=this.sum=this.max=val;
}
public void setval(long val)
{
this.left=this.right=this.sum=this.max=val;
}
public void merge(Tree left,Tree right)
{
this.sum=left.sum+ right.sum;
this.
right=Math.
max(right.
right, right.
sum+left.
right); this.
left=Math.
max(left.
left, left.
sum+right.
left); this.
max=Math.
max(Math.
max(left.
max, right.
max),
left.right+right.left);
}
}
class Ideone
{
static long a[];
static Tree[] tree;
public static void build(int node,int start,int end)
{
int mid=(start+end)>>1;
if(start==end)
{
tree[node]=new Tree(a[start]);
return;
}
build(node<<1,start,mid);
build(node<<1 + 1,mid+1,end);
tree[node]=new Tree();
tree[node].merge(tree[node<<1], tree[node<<1 + 1]);
}
public static Tree query(int node,int start,int end,int l ,int r)
{
int mid=(start+end)>>1;
if(start >=l && end<=r) return tree[node];
else if(start > r || end<l) return null;
Tree left=null, right=null;
if(l<=mid)
left=query(node<<1,start,mid,l,r);
if(r>mid)
right=query(node<<1 + 1,mid+1,end,l,r);
if(left==null) return right;
if(right==null) return left;
Tree t=new Tree();
t.merge(left, right);
return t;
}
public static void update(int node,int start,int end, int index,int val)
{
int mid=(start+end)>>1;
if(start==end) {tree[node].setval(val); return;}
if(index>=start && index<=mid) update(node<<1,start,mid,index,val);
if(index > mid && index<=end) update(node<<1 + 1,mid+1,end,index,val);
tree[node].merge(tree[node<<1],tree[node<<1 + 1]);
}
{
InputReader s = new InputReader(inputStream);
int n=s.nextInt();
a=new long[n+1];
tree= new Tree[10000000];
for(int i=1;i<=n;i++)
a[i]=s.nextLong();
build(1,1,n);
int q=s.nextInt();
while(q!=0)
{
int w=s.nextInt();
if(w==1)
{
int l=s.nextInt();
int r=s.nextInt();
Tree x=query(1,1,n,l,r);
}
else
{
int index=s.nextInt();
int val=s.nextInt();
update(1,1,n,index,val);
}
q--;
}
}
static class InputReader {
tokenizer = null;
}
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
}
}
return tokenizer.nextToken();
}
public int nextInt() {
}
public long nextLong() {
return Long.
parseLong(next
()); }
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgovKiBOYW1lIG9mIHRoZSBjbGFzcyBoYXMgdG8gYmUgIk1haW4iIG9ubHkgaWYgdGhlIGNsYXNzIGlzIHB1YmxpYy4gKi8KY2xhc3MgVHJlZQp7Cglsb25nIGxlZnQ7Cglsb25nIHJpZ2h0OwoJbG9uZyBzdW07Cglsb25nIG1heDsKCQoJcHVibGljIFRyZWUoKQoJewoJCXRoaXMubGVmdD10aGlzLnJpZ2h0PXRoaXMuc3VtPXRoaXMubWF4PUludGVnZXIuTUlOX1ZBTFVFOwoJfQkKCXB1YmxpYyBUcmVlKGxvbmcgdmFsKQoJewoJCXRoaXMubGVmdD10aGlzLnJpZ2h0PXRoaXMuc3VtPXRoaXMubWF4PXZhbDsKCX0JCglwdWJsaWMgdm9pZCBzZXR2YWwobG9uZyB2YWwpCgl7CgkJdGhpcy5sZWZ0PXRoaXMucmlnaHQ9dGhpcy5zdW09dGhpcy5tYXg9dmFsOwoJfQoJcHVibGljIHZvaWQgbWVyZ2UoVHJlZSBsZWZ0LFRyZWUgcmlnaHQpCgl7CgkJdGhpcy5zdW09bGVmdC5zdW0rIHJpZ2h0LnN1bTsKCQl0aGlzLnJpZ2h0PU1hdGgubWF4KHJpZ2h0LnJpZ2h0LCByaWdodC5zdW0rbGVmdC5yaWdodCk7CgkJdGhpcy5sZWZ0PU1hdGgubWF4KGxlZnQubGVmdCwgbGVmdC5zdW0rcmlnaHQubGVmdCk7CgkJdG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0U3RyZWFtKTsKICAgICAgCiAgICAgICBpbnQgbj1zLm5leHRJbnQoKTsgCiAgICAgICBhPW5ldyBsb25nW24rMV07CgkgICAKICAgICAgIHRyZWU9IG5ldyBUcmVlWzEwMDAwMDAwXTsKICAgICAgIAogICAgICAgZm9yKGludCBpPTE7aTw9bjtpKyspCiAgICAgICAgICAgIGFbaV09cy5uZXh0TG9uZygpOwogICAKICAgICAgIGJ1aWxkKDEsMSxuKTsKICAgICAgIAogICAgICAgaW50IHE9cy5uZXh0SW50KCk7CiAgICAgICB3aGlsZShxIT0wKQogICAgICAgewogICAgCSAgICBpbnQgdz1zLm5leHRJbnQoKTsKICAgIAkgICAgaWYodz09MSkKICAgIAkgICAgewogICAgCSAgICAJCiAgCSAgICBpbnQgbD1zLm5leHRJbnQoKTsgICAgCSAgICAKICAgIAkgICAgaW50IHI9cy5uZXh0SW50KCk7CiAgICAJICAgIFRyZWUgeD1xdWVyeSgxLDEsbixsLHIpOyAJICAgIAogICAgCSAgICBTeXN0ZW0ub3V0LnByaW50bG4oeC5tYXgpOwogICAgCSAgICAKICAgIAkgICAgfQogICAgCSAgICBlbHNlCiAgICAJICAgIHsKICAgIAkgICAgCWludCBpbmRleD1zLm5leHRJbnQoKTsKICAgIAkgICAgCWludCB2YWw9cy5uZXh0SW50KCk7CiAgICAJICAgIAl1cGRhdGUoMSwxLG4saW5kZXgsdmFsKTsKICAgIAkgICAgfQogICAgCSAgICBxLS07CiAgICAgICB9ICAgICAgCSAKICAgICAgIH0KICAgCiAgIHN0YXRpYyBjbGFzcyBJbnB1dFJlYWRlciB7CiAgICAgICBwdWJsaWMgQnVmZmVyZWRSZWFkZXIgcmVhZGVyOwogICAgICAgcHVibGljIFN0cmluZ1Rva2VuaXplciB0b2tlbml6ZXI7CgogICAgICAgcHVibGljIElucHV0UmVhZGVyKElucHV0U3RyZWFtIHN0cmVhbSkgewogICAgICAgICAgIHJlYWRlciA9IG5ldyBCdWZmZXJlZFJlYWRlcihuZXcgSW5wdXRTdHJlYW1SZWFkZXIoc3RyZWFtKSwgMzI3NjgpOwogICAgICAgICAgIHRva2VuaXplciA9IG51bGw7CiAgICAgICB9CgogICAgICAgcHVibGljIFN0cmluZyBuZXh0KCkgewogICAgICAgICAgIHdoaWxlICh0b2tlbml6ZXIgPT0gbnVsbCB8fCAhdG9rZW5pemVyLmhhc01vcmVUb2tlbnMoKSkgewogICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgdG9rZW5pemVyID0gbmV3IFN0cmluZ1Rva2VuaXplcihyZWFkZXIucmVhZExpbmUoKSk7CiAgICAgICAgICAgICAgIH0gY2F0Y2ggKElPRXhjZXB0aW9uIGUpIHsKICAgICAgICAgICAgICAgICAgIHRocm93IG5ldyBSdW50aW1lRXhjZXB0aW9uKGUpOwogICAgICAgICAgICAgICB9CiAgICAgICAgICAgfQogICAgICAgICAgIHJldHVybiB0b2tlbml6ZXIubmV4dFRva2VuKCk7CiAgICAgICB9CgogICAgICAgcHVibGljIGludCBuZXh0SW50KCkgewogICAgICAgICAgIHJldHVybiBJbnRlZ2VyLnBhcnNlSW50KG5leHQoKSk7CiAgICAgICB9CiAgICAgICAKICAgICAgIHB1YmxpYyBsb25nIG5leHRMb25nKCkgewogICAgICAgICAgIHJldHVybiBMb25nLnBhcnNlTG9uZyhuZXh0KCkpOwogICAgICAgfQogICB9Cn0KICAgICAgIA==