#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 10;
long long a[N], t[N], n, qwq[N];
map<pair<long long, long long>, long long> mp;
long long query(long long x) {
  long long ans = 0;
  while (x) {
    ans += t[x];
    x -= x & (-x);
  }
  return ans;
}
void add(long long x, long long d) {
  if (!x) return;
  d = max(d, query(x - 1) - query(x));
  while (x <= n) {
    t[x] += d;
    x += x & (-x);
  }
}
signed main() {
  long long x, y, z, q;
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    add(i, a[i]);
    qwq[i] = a[i];
  }
  scanf("%lld", &q);
  while (q--) {
    scanf("%lld%lld%lld", &x, &y, &z);
    long long pre = mp[make_pair(x, y)];
    if (qwq[pre] >= 0) add(pre, 1);
    add(z, -1);
    mp[make_pair(x, y)] = z;
    qwq[pre]++, qwq[z]--;
    printf("%lld\n", query(n));
  }
  return 0;
}
