/* -*- coding: utf-8 -*- * * 3164.cc: No.3164 [Chery 7th Tune B] La vie en rose - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_N = 300000; /* typedef */ using ll = long long; /* global variables */ int as[MAX_N]; ll ass[MAX_N]; /* subroutines */ /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", as + i); for (int i = 0; i < n;) { while (i < n && as[i] == 0) i++; if (i >= n) break; int j = i; ll s = 0; while (i < n && as[i] > 0) s += as[i++]; while (j < i) ass[j++] = s; } int qn; scanf("%d", &qn); while (qn--) { int x, b; scanf("%d%d", &x, &b), x--; ll s = ass[x] - as[x] + b; if (as[x] == 0) { if (x > 0 && as[x - 1] > 0) s += ass[x - 1]; if (x + 1 < n && as[x + 1] > 0) s += ass[x + 1]; } printf("%lld\n", s); } return 0; }