#include #define all(vec) vec.begin(), vec.end() using namespace std; using ll = long long; using P = pair; constexpr ll INF = (1LL << 30) - 1LL; constexpr ll LINF = (1LL << 60) - 1LL; constexpr double eps = 1e-9; constexpr ll MOD = 1000000007LL; template bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }; template bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }; template ostream &operator<<(ostream &os, vector v) { for (int i = 0; i < v.size(); i++) { os << v[i] << (i + 1 == v.size() ? "\n" : " "); } return os; } template vector make_v(size_t a) { return vector(a); } template auto make_v(size_t a, Ts... ts) { return vector(ts...))>(a, make_v(ts...)); } template typename enable_if::value == 0>::type fill_v(T &t, const V &v) { t = v; } template typename enable_if::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) { fill_v(e, v); } }; template struct RangeMax { using T = U; static T op(const T &a, const T &b) { return max(a, b); } static constexpr T id() { return -INF; } }; template struct Segtree { using T = typename Monoid::T; int n; vector dat; Segtree(int n_) { n = 1; while (n < n_) n <<= 1; dat.resize(2 * n, Monoid::id()); } T get(int k) { assert(k < n); return dat[k + n]; } void set(int k, const T &x) { assert(k < n); k += n; dat[k] = x; for (k >>= 1; k > 0; k >>= 1) { dat[k] = Monoid::op(dat[k << 1], dat[k << 1 | 1]); } } void add(int k, const T &x) { assert(k < n); k += n; dat[k] += x; for (k >>= 1; k > 0; k >>= 1) { dat[k] = Monoid::op(dat[k << 1], dat[k << 1 | 1]); } } T query(int a, int b) { //[a,b]->[a,b) if (a < 0) a = 0; if (a > b) return Monoid::id(); if (b > n) b = n; T vl = Monoid::id(), vr = Monoid::id(); int l = a + n, r = b + n + 1; for (; l < r; l >>= 1, r >>= 1) { if (l & 1) vl = Monoid::op(vl, dat[l++]); if (r & 1) vr = Monoid::op(dat[--r], vr); } return Monoid::op(vl, vr); } }; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector a(n + 1), sum(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; sum[i] = sum[i - 1] + a[i]; } Segtree> seg(n + 10); for (int i = 24; i <= n; i++) { seg.set(i, sum[i] - sum[i - 24]); } int q; cin >> q; while (q--) { int t, v; cin >> t >> v; int to = v - a[t]; a[t] = v; for (int i = max(t, 24); i < min(n + 1, t + 24); i++) { seg.add(i, to); } cout << seg.query(0, n + 1) << endl; } }