#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 2, inf = 1e9;
int a[N];
int n, q;
struct data {
  long long v, ex;
} s[4 * N];
void build(int id = 1, int l = 0, int r = n - 1) {
  if (r == l) {
    s[id].v = a[r];
    s[id].ex = 0;
    return;
  }
  int mid = (l + r) / 2;
  build(2 * id, l, mid);
  build(2 * id + 1, mid + 1, r);
  s[id].v = s[2 * id].v + s[2 * id + 1].v;
}
void update(int pos, int x, int id = 1, int l = 0, int r = n - 1) {
  if (!(l <= pos and pos <= r)) return;
  if (l == r and r == pos) {
    x == 1 ? (s[id].ex > 0 ? s[id].ex-- : s[id].v++)
           : (s[id].v == 0 ? s[id].ex++ : s[id].v--);
    return;
  }
  int mid = (l + r) / 2;
  update(pos, x, 2 * id, l, mid);
  update(pos, x, 2 * id + 1, mid + 1, r);
  s[id].v = s[2 * id].v + s[2 * id + 1].v;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  build();
  cin >> q;
  map<pair<int, int>, int> m;
  while (q--) {
    int S, T, U;
    cin >> S >> T >> U;
    auto it = m.find({S, T});
    if (it != m.end()) {
      int p = a[S - 1];
      int z = it->second;
      m.erase(it);
      if (p >= T) {
        update(z - 1, 1);
      }
    }
    if (U != 0) {
      m.insert({{S, T}, U});
      int p = a[S - 1];
      if (p >= T) {
        update(U - 1, -1);
      }
    }
    cout << s[1].v << "\n";
  }
  return 0;
}
