#include <iostream>
#include <cmath>
using namespace std;
struct data {
int sum, pref, suff, ans;
};
data combine (data l, data r) {
data res;
res.sum = l.sum + r.sum;
res.pref = max (l.pref, l.sum + r.pref);
res.suff = max (r.suff, r.sum + l.suff);
res.ans = max (max (l.ans, r.ans), l.suff + r.pref);
return res;
}
data make_data (int val) {
data res;
res.sum = val;
res.pref = res.suff = res.ans = val;
return res;
}
void build (int a[], int v, int tl, int tr, data t[]) {
if (tl == tr)
t[v] = make_data (a[tl]);
else {
int tm = (tl + tr) / 2;
build (a, v*2, tl, tm, t);
build (a, v*2+1, tm+1, tr, t);
t[v] = combine (t[v*2], t[v*2+1]);
}
}
void update (int v, int tl, int tr, int pos, int new_val, data t[]) {
if (tl == tr)
t[v] = make_data (new_val);
else {
int tm = (tl + tr) / 2;
if (pos <= tm)
update (v*2, tl, tm, pos, new_val, t);
else
update (v*2+1, tm+1, tr, pos, new_val, t);
t[v] = combine (t[v*2], t[v*2+1]);
}
}
data query (int v, int tl, int tr, int l, int r, data t[]) {
if (l == tl && tr == r)
return t[v];
int tm = (tl + tr) / 2;
if (r <= tm)
return query (v*2, tl, tm, l, r, t);
if (l > tm)
return query (v*2+1, tm+1, tr, l, r, t);
return combine (
query (v*2, tl, tm, l, tm, t),
query (v*2+1, tm+1, tr, tm+1, r, t)
);
}
int main() {
int n, m, x, y;
cin >> n;
int* a = new int[n];
for(int i = 0; i < n; i++) {
cin >> a[i];
}
data* t = new data[4*n];
build(a, 1, 0, n-1, t);
cin >> m ;
bool oper;
for(int i = 0; i < m; i++) {
cin >> oper >> x >> y;
if(!oper) {
update (1, 0, n-1, x-1, y, t);
} else if(oper) {
cout << query (1, 0, n-1, x-1, y-1, t).ans << endl;
}
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y21hdGg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnN0cnVjdCBkYXRhIHsKCWludCBzdW0sIHByZWYsIHN1ZmYsIGFuczsKfTsKZ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