#include <fstream>
using namespace std;
class InputReader {
public:
InputReader() {}
InputReader(const char *file_name) {
input_file = fopen(file_name, "r");
cursor = 0;
fread(buffer, SIZE, 1, input_file);
}
inline InputReader &operator >>(int &n) {
while((buffer[cursor] < '0' || buffer[cursor] > '9')&& buffer[cursor]!='-') {
advance();
}
semn=1;
if(buffer[cursor]=='-')
{
semn=-1;
advance();
}
n = 0;
while('0' <= buffer[cursor] && buffer[cursor] <= '9') {
n = n * 10 + buffer[cursor] - '0';
advance();
}
n*=semn;
return *this;
}
private:
FILE *input_file;
static const int SIZE = 1 << 20;
int cursor,semn;
char buffer[SIZE];
inline void advance() {
++ cursor;
if(cursor == SIZE) {
cursor = 0;
fread(buffer, SIZE, 1, input_file);
}
}
}f("maxq.in");
ofstream g("maxq.out");
int a,b,n,m,x,tip;
long long sol,S;
inline long long maxi(long long a,long long b)
{
return (a>b?a:b);
}
struct aint
{
int best,sum,st,dr;
inline void init(int val)
{
best=sum=st=dr=val;
}
inline void up(aint a,aint b)
{
sum=a.sum+b.sum;
best=maxi(maxi(a.best,b.best),a.dr+b.st);
st=maxi(a.st,a.sum+b.st);
dr=maxi(b.dr,a.dr+b.sum);
}
}AI[1<<19];
inline void build(int nod,int st,int dr)
{
if(st==dr)
{
f>>x;
AI[nod].init(x);
return ;
}
int mid=(st+dr)>>1;
build(nod<<1,st,mid);
build((nod<<1)+1,mid+1,dr);
AI[nod].up(AI[nod<<1],AI[(nod<<1)+1]);
}
inline void query(int nod,int st,int dr)
{
if(a<=st&&dr<=b)
{
if(S<0) S=0;
sol=maxi(sol,maxi(AI[nod].best,S+AI[nod].st));
S=maxi(S+AI[nod].sum,AI[nod].dr);
return ;
}
int mid=(st+dr)>>1;
if(a<=mid) query(nod<<1,st,mid);
if(b>mid) query((nod<<1)+1,mid+1,dr);
}
inline void update(int nod,int st,int dr)
{
if(st==dr)
{
AI[nod].init(b-1);
return ;
}
int mid=(st+dr)>>1;
if(a<=mid) update(nod<<1,st,mid);
else update((nod<<1)+1,mid+1,dr);
AI[nod].up(AI[nod<<1],AI[(nod<<1)+1]);
}
int main()
{
f>>n;
build(1,1,n);
f>>m;
while(m--)
{
f>>tip>>a>>b;
++a;
++b;
if(tip==1)
{
sol=S=0;
query(1,1,n);
g<<sol<<'\n';
}
else update(1,1,n);
}
return 0;
}