#include using namespace std; #define ALL(x) begin(x),end(x) #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<bool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(b ostream &operator<<(ostream &os,const vector&v){ for(int i=0;i<(int)v.size();i++) os< istream &operator>>(istream &is,vector&v){ for(T &x:v)is>>x; return is; } template struct SegmentTree{ using F=function; int sz; vector seg; const F f; const Monoid gen; SegmentTree(int n,const F f,const Monoid &gen):f(f),gen(gen){ sz=1; while(sz0;k--) seg[k]=f(seg[2*k],seg[2*k+1]); } void update(int k,const Monoid &x){ k+=sz; seg[k]=x; while(k>>=1) seg[k]=f(seg[2*k],seg[2*k+1]); } // [a,b) Monoid query(int a,int b){ Monoid L=gen,R=gen; for(a+=sz,b+=sz;a>=1,b>>=1){ if(a&1) L=f(L,seg[a++]); if(b&1) R=f(seg[--b],R); } return f(L,R); } Monoid operator[](const int &k)const { return seg[k+sz]; } }; ll f(ll a,ll b){ return (a>b?a:b); } signed main(){ int n;cin>>n; vector a(n); cin>>a; int sz=n-23; SegmentTree seg(n,f,-LINF); rep(i,sz) seg.set(i,0); rep(i,n)for(int j=max(0,i-24+1);j<=min(sz,i);j++) seg.set(j,seg[j]+a[i]); seg.build(); int q;cin>>q; while(q--){ int idx;ll k;cin>>idx>>k;idx--; ll dif=k-a[idx];a[idx]=k; for(int j=max(0,idx-24+1);j<=min(sz,idx);j++) seg.update(j,seg[j]+dif); cout<