#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
const int maxn = 50050;
int n, m, x, y, op, val[maxn];
struct SegNode {
int left, right, sum, maxLeft, maxRight, maxAll;
int mid() { return (left + right) >> 1; }
};
struct SegmentTree {
SegNode tree[maxn*5];
SegNode pushUp(SegNode left, SegNode right) {
SegNode update;
update.sum = left.sum + right.sum;
update.maxLeft = max(left.maxLeft, left.sum + right.maxLeft);
update.maxRight = max(right.maxRight, right.sum + left.maxRight);
update.maxAll = max(max(left.maxAll, right.maxAll), left.maxRight + right.maxLeft);
return update;
}
void build(int left, int right, int idx) {
tree[idx].left = left; tree[idx].right = right;
if (left == right) {
tree[idx].sum = tree[idx].maxLeft = tree[idx].maxRight = tree[idx].maxAll = val[left];
return ;
}
int mid = tree[idx].mid();
build(left, mid, idx<<1); build(mid+1, right, idx<<1|1);
SegNode update = pushUp(tree[idx<<1], tree[idx<<1|1]);
tree[idx].sum = update.sum; tree[idx].maxLeft = update.maxLeft;
tree[idx].maxRight = update.maxRight; tree[idx].maxAll = update.maxAll;
}
void update(int pos, int value, int idx) {
if (tree[idx].left == tree[idx].right) {
tree[idx].maxAll = value; tree[idx].sum = value; tree[idx].maxLeft = value;
tree[idx].maxRight = value; return ;
}
int mid = tree[idx].mid();
if (pos <= mid) update(pos, value, idx<<1);
else update(pos, value, idx<<1|1);
SegNode update = pushUp(tree[idx<<1], tree[idx<<1|1]);
tree[idx].sum = update.sum; tree[idx].maxLeft = update.maxLeft;
tree[idx].maxRight = update.maxRight; tree[idx].maxAll = update.maxAll;
}
SegNode query(int left, int right, int idx) {
if (tree[idx].left >= left && tree[idx].right <= right)
return tree[idx];
int mid = tree[idx].mid();
if (right <= mid) return query(left, right, idx<<1);
else if (left > mid) return query(left, right, idx<<1|1);
else return pushUp(query(left, mid, idx<<1), query(mid+1, right, idx<<1|1));
}
};
SegmentTree seg;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", val + i);
seg.build(1, n, 1); scanf("%d", &m);
for (int i = 1; i <= m; i++) {
scanf("%d %d %d", &op, &x, &y);
if (op == 1) printf("%d\n", seg.query(x, y, 1).maxAll);
else seg.update(x, y, 1);
}
return 0;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGNzdHJpbmc+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDxxdWV1ZT4KI2luY2x1ZGUgPHZlY3Rvcj4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNvbnN0IGludCBtYXhuID0gNTAwNTA7CmludCBuLCBtLCB4LCB5LCBvcCwgdmFsW21heG5dOwoKc3RydWN0IFNlZ05vZGUgewoJaW50IGxlZnQsIHJpZ2h0LCBzdW0sIG1heExlZnQsIG1heFJpZ2h0LCBtYXhBbGw7CglpbnQgbWlkKCkgeyByZXR1cm4gKGxlZnQgKyByaWdodCkgPj4gMTsgfQp9OwoKc3RydWN0IFNlZ21lbnRUcmVlIHsKCglTZWdOb2RlIHRyZWVbbWF4bio1XTsKCglTZWdOb2RlIHB1c2hVcChTZWdOb2RlIGxlZnQsIFNlZ05vZGUgcmlnaHQpIHsKCQlTZWdOb2RlIHVwZGF0ZTsKCQl1cGRhdGUuc3VtID0gbGVmdC5zdW0gKyByaWdodC5zdW07CgkJdXBkYXRlLm1heExlZnQgPSBtYXgobGVmdC5tYXhMZWZ0LCBsZWZ0LnN1bSArIHJpZ2h0Lm1heExlZnQpOwoJCXVwZGF0ZS5tYXhSaWdodCA9IG1heChyaWdodC5tYXhSaWdodCwgcmlnaHQuc3VtICsgbGVmdC5tYXhSaWdodCk7CgkJdXBkYXRlLm1heEFsbCA9IG1heChtYXgobGVmdC5tYXhBbGwsIHJpZ2h0Lm1heEFsbCksIGxlZnQubWF4UmlnaHQgKyByaWdodC5tYXhMZWZ0KTsKCQlyZXR1cm4gdXBkYXRlOwoJfQoKCXZvaWQgYnVpbGQoaW50IGxlZnQsIGludCByaWdodCwgaW50IGlkeCk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