#include #define rep(i, n) for (int i = 0; i < (n); i++) #define repr(i, n) for (int i = (n) - 1; i >= 0; i--) using namespace std; using ll = long long; const int U = 1 << 18; int dat[U * 2]; void update(int k, int v) { k += U; dat[k] = v; while (k > 1) { k >>= 1; dat[k] = max(dat[k * 2], dat[k * 2 + 1]); } } int query(int l, int r) { l += U; r += U - 1; int ans = 0; for (; l <= r; l >>= 1, r >>= 1) { if ((l & 1) == 1) ans = max(ans, dat[l++]); if ((r & 1) == 0) ans = max(ans, dat[r--]); } return ans; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N; cin >> N; vector A(N); rep(i, N) cin >> A[i]; int Q; cin >> Q; auto calc = [&](int i) -> int { int ans = 0; rep(j, 24) ans += A[i + j]; return ans; }; rep(i, N-24+1) { update(i, calc(i)); } while (Q--) { int T, V; cin >> T >> V; A[T - 1] = V; for (int i = min(N - 24, T); i >= max(0, T - 23); i--) { update(i, calc(i)); } cout << query(0, N - 24 + 1) << '\n'; } }