func_code_string: #include <bits/stdc++.h>   using namespace std;   int const N = 100000;   long long a[N + 1];   long long f[N * 3];   inline int lc(int root) { return root << 1; }   inline int rc(int root) { return (root << 1) | 1; }   void build(int root, int l, int r) {     f[root] = -1;     if (l == r) {       f[root] = a[l];       return;     }     int mid = (l + r) >> 1;     build(lc(root), l, mid);     build(rc(root), mid + 1, r);     if (f[lc(root)] == f[rc(root)]) {       f[root] = f[lc(root)];     }   }   void update(int root, int l, int r, int fi, int la, long long val) {     if (fi == l && la == r) {       f[root] = val;       return;     }     int mid = (l + r) >> 1;     f[root] = -1;     if (fi > mid) {       update(rc(root), mid + 1, r, fi, la, val);     } else if (la <= mid) {       update(lc(root), l, mid, fi, la, val);     } else {       update(lc(root), l, mid, fi, mid, val);       update(rc(root), mid + 1, r, mid + 1, la, val);     }     if (f[lc(root)] == f[rc(root)]) {       f[root] = f[lc(root)];     }   }   long long query(int root, int l, int r, int fi, int la) {     if (f[root] != -1) {       return f[root];     }     int mid = (l + r) >> 1;     if (fi > mid) {       return query(rc(root), mid + 1, r, fi, la);     } else if (la <= mid) {       return query(lc(root), l, mid, fi, la);     } else {       return max(query(lc(root), l, mid, fi, mid),                  query(rc(root), mid + 1, r, mid + 1, la));     }   }   void work() {     int n;     int m;     long long w, h;     long long res;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %I64d , &a[i]);     }     build(1, 1, n);     scanf( %d , &m);     while (m--) {       scanf( %I64d%I64d , &w, &h);       res = query(1, 1, n, 1, w);       printf( %I64d n , res);       update(1, 1, n, 1, w, res + h);     }   }   int main() {     work();     return 0;   }   