#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MAXI (7e8)
#define N 50010
int n, a[N];
struct node{
int sum, prefix, suffix, ans;
};
node seg[5*N];
node data(int x)
{
node pawan;
pawan.sum = pawan.prefix = pawan.suffix = pawan.ans = x;
return pawan;
}
node merge(node x, node y)
{
node pawan;
if(x.sum==-MAXI)
{
pawan.sum = y.sum;
pawan.prefix = y.prefix;
pawan.suffix = max(y.suffix , y.sum);
pawan.ans = max(y.ans,y.prefix);
}
else
if(y.sum == -MAXI)
{
pawan.sum = x.sum;
pawan.prefix = x.prefix;
pawan.suffix = max(x.suffix , x.sum);
pawan.ans = max(x.ans,x.prefix);
}
else
{
pawan.sum = x.sum + y.sum;
pawan.prefix = max(x.prefix , x.sum + y.prefix);
pawan.suffix = max(y.suffix , y.sum + x.suffix);
pawan.ans = max(max(x.ans, y.ans) , x.suffix + y.prefix);
}
return pawan;
}
void build(int id, int l, int r)
{
if(l==r)
{
seg[id] = data(a[l]);
return ;
}
int mid = (l+r)/2;
build(2 * id,l,mid);
build(2 * id + 1,mid+1,r);
seg[id] = merge(seg[2*id], seg[2*id+1]);
}
void update(int x, int y, int id, int l, int r)
{
if(l==r)
{
seg[id] = data(y);
return ;
}
int mid = (l+r)/2;
if(x<=mid)
update(x,y,2 * id,l,mid);
else
update(x,y,2 * id + 1,mid+1,r);
seg[id] = merge(seg[2*id], seg[2*id+1]);
}
node segment(int x, int y, int id, int l, int r)
{
if(l>r or l > y || x > r)
return data(-MAXI);
if(x <= l && r <= y)
return seg[id];
int mid = (l+r)/2;
node a = segment(x,y,2 * id,l,mid);
node b = segment(x,y,2 * id + 1,mid+1,r);
return merge(a,b);
}
// Driver code to test above functions
int32_t main()
{
#ifndef ONLINE_JUDGE
// for getting input from inpu.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
//freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
for(int i=0;i<n;i++)
cin >> a[i];// a[i];
build(1,0,n-1);
int q;
cin >> q;
while(q--)
{
int type, x, y;
cin >> type >> x >> y;
x--;y--;
if(type==0)
{
y++;
update(x,y,1,0,n-1);
}
else
cout << segment(x,y,1,0,n-1).ans << endl;
}
return 0;
}
ICNpbmNsdWRlPGJpdHMvc3RkYysrLmg+CiAgICAgICAgdXNpbmcgbmFtZXNwYWNlIHN0ZDsKICAgICAgICAjZGVmaW5lIGludCBsb25nIGxvbmcKICAgICAgICAjZGVmaW5lIE1BWEkgKDdlOCkKICAgICAgICAjZGVmaW5lIE4gNTAwMTAKICAgICAgICAgCiAgICAgICAgaW50IG4sIGFbTl07CiAgICAgICAgIAogICAgICAgIHN0cnVjdCBub2RlewogICAgICAgICAgICBpbnQgc3VtLCBwcmVmaXgsIHN1ZmZpeCwgYW5zOwogICAgICAgIH07CiAgICAgICAgIAogICAgICAgIG5vZGUgc2VnWzUqTl07CiAgICAgICAgIAogICAgICAgIG5vZGUgZGF0YShpbnQgeCkKICAgICAgICB7CiAgICAgICAgICAgIG5vZGUgcGF3YW47CiAgICAgICAgICAgIHBhd2FuLnN1bSA9IHBhd2FuLnByZWZpeCA9IHBhd2FuLnN1ZmZpeCA9IHBhd2FuLmFucyA9IHg7CiAgICAgICAgICAgIHJldHVybiBwYXdhbjsKICAgICAgICB9CiAgICAgICAgIAogICAgICAgIG5vZGUgbWVyZ2Uobm9kZSB4LCBub2RlIHkpCiAgICAgICAgewogICAgICAgICAgICBub2RlIHBhd2FuOwogICAgICAgICAgICAgCiAgICAgICAgICAgIGlmKHguc3VtPT0tTUFYSSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgcGF3YW4uc3VtID0geS5zdW07CiAgICAgICAgICAgICAgICBwYXdhbi5wcmVmaXggPSB5LnByZWZpeDsKICAgICAgICAgICAgICAgIHBhd2FuLnN1ZmZpeCA9IG1heCh5LnN1ZmZpeCAsIHkuc3VtKTsKICAgICAgICAgICAgICAgIHBhd2FuLmFucyA9IG1heCh5LmFucyx5LnByZWZpeCk7ICAgIAogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgaWYoeS5zdW0gPT0gLU1BWEkpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHBhd2FuLnN1bSA9IHguc3VtOwogICAgICAgICAgICAgICAgcGF3YW4ucHJlZml4ID0geC5wcmVmaXg7CiAgICAgICAgICAgICAgICBwYXdhbi5zdWZmaXggPSBtYXgoeC5zdWZmaXggLCB4LnN1bSk7CiAgICAgICAgICAgICAgICBwYXdhbi5hbnMgPSBtYXgoeC5hbnMseC5wcmVmaXgpOyAKICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHBhd2FuLnN1bSA9IHguc3VtICsgeS5zdW07CiAgICAgICAgICAgICAgICBwYXdhbi5wcmVmaXggPSBtYXgoeC5wcmVmaXggLCB4LnN1bSArIHkucHJlZml4KTsKICAgICAgICAgICAgICAgIHBhd2FuLnN1ZmZpeCA9IG1heCh5LnN1ZmZpeCAsIHkuc3VtICsgeC5zdWZmaXgpOwogICAgICAgICAgICAgICAgcGF3YW4uYW5zID0gbWF4KG1heCh4LmFucywgeS5hbnMpICwgeC5zdWZmaXggKyB5LnByZWZpeCk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgIAogICAgICAgICAgICByZXR1cm4gcGF3YW47CiAgICAgICAgfQogICAgICAgICAKICAgICAgICB2b2lkIGJ1aWxkKGludCBpZCwgaW50IGwsIGludCByKQogICAgICAgIHsKICAgICAgICAgCiAgICAgICAgICAgIGlmKGw9PXIpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHNlZ1tpZF0gPSBkYXRhKGFbbF0pOwogICAgICAgICAgICAgICAgcmV0dXJuIDsKICAgICAgICAgICAgfQogICAgICAgICAgICBpbnQgbWlkID0gKGwrcikvMjsKICAgICAgICAgICAgYnVpbGQoMiAqIGlkLGwsbWlkKTsKICAgICAgICAgICAgYnVpbGQoMiAqIGlkICsgMSxtaWQrMSxyKTsKICAgICAgICAgICAKICAgICAgICAgICAgc2VnW2lkXSA9IG1lcmdlKHNlZ1syKmlkXSwgc2VnWzIqaWQrMV0pOwogICAgICAgICAgIAogICAgICAgIH0KICAgICAgICAgCiAgICAgICAgdm9pZCB1cGRhdGUoaW50IHgsIGludCB5LCBpbnQgaWQsIGludCBsLCBpbnQgcikKICAgICAgICB7ICAgIAogICAgIAogICAgICAgICAgICBpZihsPT1yKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBzZWdbaWRdID0gZGF0YSh5KTsKICAgICAgICAgICAgICAgIHJldHVybiA7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICBpbnQgbWlkID0gKGwrcikvMjsKICAgICAgICAgICAgaWYoeDw9bWlkKQogICAgICAgICAgICAgICAgdXBkYXRlKHgseSwyICogaWQsbCxtaWQpOwogICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICB1cGRhdGUoeCx5LDIgKiBpZCArIDEsbWlkKzEscik7CiAgICAgICAgICAgICAKICAgICAgICAgICAgc2VnW2lkXSA9IG1lcmdlKHNlZ1syKmlkXSwgc2VnWzIqaWQrMV0pOwogICAgICAgIH0KICAgICAgICAgCiAgICAgICAgbm9kZSBzZWdtZW50KGludCB4LCBpbnQgeSwgaW50IGlkLCBpbnQgbCwgaW50IHIpCiAgICAgICAgewogICAgICAgICAgICBpZihsPnIgb3IgbCA+IHkgfHwgeCA+IHIpICAKICAgICAgICAgICAgICAgIHJldHVybiBkYXRhKC1NQVhJKTsKICAgICAgICAgCiAgICAgICAgICAgIGlmKHggPD0gbCAmJiByIDw9IHkpCiAgICAgICAgICAgICAgICByZXR1cm4gc2VnW2lkXTsKICAgICAgICAgCiAgICAgICAgICAgIGludCBtaWQgPSAobCtyKS8yOwogICAgICAgICAgICBub2RlIGEgPSBzZWdtZW50KHgseSwyICogaWQsbCxtaWQpOwogICAgICAgICAgICBub2RlIGIgPSBzZWdtZW50KHgseSwyICogaWQgKyAxLG1pZCsxLHIpOwogICAgICAgICAKICAgICAgICAgICAgcmV0dXJuIG1lcmdlKGEsYik7ICAKICAgICAgICB9CiAgICAgICAgIAogICAgICAgICAKICAgICAgICAvLyBEcml2ZXIgY29kZSB0byB0ZXN0IGFib3ZlIGZ1bmN0aW9ucwogICAgICAgIGludDMyX3QgbWFpbigpCiAgICAgICAgewogICAgICAgICAKICAgICAgICAgICAgI2lmbmRlZiBPTkxJTkVfSlVER0UKICAgICAgICAgICAgLy8gZm9yIGdldHRpbmcgaW5wdXQgZnJvbSBpbnB1LnR4dAogICAgICAgICAgICBmcmVvcGVuKCJpbnB1dC50eHQiLCAiciIsIHN0ZGluKTsKICAgICAgICAgICAgLy8gZm9yIHdyaXRpbmcgb3V0cHV0IHRvIG91dHB1dC50eHQKICAgICAgICAgICAgLy9mcmVvcGVuKCJvdXRwdXQudHh0IiwgInciLCBzdGRvdXQpOwogICAgICAgICAgICAjZW5kaWYKICAgICAgICAgCiAgICAgICAgICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oMCk7CiAgICAgICAgICAgIGNpbi50aWUoTlVMTCk7CiAgICAgICAgICAgIGNvdXQudGllKE5VTEwpOwogICAgICAgICAKICAgICAgICAgICAgY2luID4+IG47CiAgICAgICAgICAgIGZvcihpbnQgaT0wO2k8bjtpKyspCiAgICAgICAgICAgICAgICBjaW4gPj4gYVtpXTsvLyBhW2ldOwogICAgICAgICAKICAgICAgICAgICAgYnVpbGQoMSwwLG4tMSk7CiAgICAgICAgIAogICAgICAgICAgICBpbnQgcTsKICAgICAgICAgICAgY2luID4+IHE7CiAgICAgICAgICAgIHdoaWxlKHEtLSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgaW50IHR5cGUsIHgsIHk7CiAgICAgICAgICAgICAgICBjaW4gPj4gdHlwZSA+PiB4ID4+IHk7CiAgICAgICAgICAgICAgICB4LS07eS0tOwogICAgICAgICAgICAgICAgaWYodHlwZT09MCkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICB5Kys7CiAgICAgICAgICAgICAgICAgICAgdXBkYXRlKHgseSwxLDAsbi0xKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgICAgICBjb3V0IDw8IHNlZ21lbnQoeCx5LDEsMCxuLTEpLmFucyA8PCBlbmRsOwogICAgICAgICAgICB9CiAgICAgICAgIAogICAgICAgICAgICByZXR1cm4gMDsgIAogICAgICAgIH0=