package no3164_la_vie_en_rose; import java.util.*; public class Main { public static void main(String[] args) { // TODO 自動生成されたメソッド・スタブ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); UnionFind uf = new UnionFind(n + 1); for(int i = 1;i <= n;i++) { uf.val[i] = Integer.parseInt(sc.next()); uf.size[i] = uf.val[i]; }for(int i = 1;i <= n;i++) { if(uf.val[i - 1] > 0 && uf.val[i] > 0) { uf.unite(i - 1, i); } }int q = sc.nextInt(); StringBuilder sb = new StringBuilder(); for(int i = 0;i < q;i++){ int ind = Integer.parseInt(sc.next()); int val = Integer.parseInt(sc.next()); long ans = 0; int root = uf.getRoot(ind); if(uf.val[ind] == 0) { int b = uf.getRoot(ind - 1); int c = uf.getRoot(ind + 1); ans = val + uf.size[b] + uf.size[c]; }else { ans = uf.size[root] + val - uf.val[ind]; } sb.append(ans + "\n"); }System.out.print(sb); }public static class UnionFind{ public int[] root; public long[] size; public long[] val; public UnionFind(int n) { this.root = new int[n + 1]; this.size = new long[n + 1]; this.val = new long[n + 1]; for(int i = 1;i < n + 1;i++) { this.root[i] = i; } } public void unite(int x,int y) { x = getRoot(x); int yc = getRoot(y); if(x != y){ size[x] += size[yc]; } this.root[yc] = this.root[x]; } public void rootPlus(int x,int y) { this.root[x] = y; this.size[y]++; } public int getRoot(int x) { if(x == this.root[x]) { return x; }else return this.root[x] = getRoot(this.root[x]); } public boolean same(int x,int y) { x = getRoot(x); y = getRoot(y); return x == y; } } }