#define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define MT make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)<; using vi = vector; using vll = vector; template class DynamicRMQ { int n; Val init; vector dat; Cmp cmp; inline Val query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return init; if (a <= l && r <= b) return dat[k]; else { Val vl, vr; vl = query(a, b, k << 1, l, (l + r) >> 1); vr = query(a, b, (k << 1) | 1, (l + r) >> 1, r); return cmp(vl, vr) ? vl : vr; } } public: DynamicRMQ() {} DynamicRMQ(int n_, Val init_) :n(1), init(init_) { for (; n(n << 1, init); } void update(int k, Val a) { k += n; dat[k] = a; while (k > 1) { k >>= 1; dat[k] = cmp(dat[k << 1], dat[(k << 1) | 1]) ? dat[k << 1] : dat[(k << 1) | 1]; } } Val query(int a, int b) { return query(a, b, 1, 0, n); } }; typedef DynamicRMQ > RMinQ64; typedef DynamicRMQ > RMaxQ64; typedef DynamicRMQ > RMinQ32; typedef DynamicRMQ > RMaxQ32; void solve() { int N; cin >> N; vll A(N); rep(i, N)cin >> A[i]; RMaxQ64 rmq(N, 0); auto f = [&](int k) { ll val = 0; FOR(i, k, min(k + 24, N)) { val += A[i]; } rmq.update(k, val); }; rep(i, N) { f(i); } int Q; cin >> Q; rep(ITER, Q) { int T, V; cin >> T >> V; --T; A[T] = V; for (int i = max(0, T - 23); i <= T; ++i) { f(i); } cout << rmq.query(0, N) << endl; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); solve(); return 0; }