/* -*- coding: utf-8 -*- * * 2306.cc: No.2306 [Cherry 5th Tune C] ウソツキタマシイ - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_M = 100000; /* typedef */ typedef long long ll; /* global variables */ int as[MAX_M]; /* subroutines */ /* main */ int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < m; i++) scanf("%d", as + i); ll sum = 0; for (int i = 0; i < m; i++) sum += (ll)as[i] * as[i]; int qn; scanf("%d", &qn); while (qn--) { int c, k, d; scanf("%d%d%d", &c, &k, &d); c--, d--; sum -= (ll)as[c] * as[c] + (ll)as[d] * as[d]; as[c] -= k, as[d] += k; sum += (ll)as[c] * as[c] + (ll)as[d] * as[d]; printf("%lld\n", sum); } return 0; }