N, M = map(int, input().split()) A = list(map(int, input().split())) ans1 = 0 for i in range(M): ans1 += A[i]*A[i] Q = int(input()) for _ in range(Q): c, k, d = map(int, input().split()) c -= 1 d -= 1 diff1 = (A[d]**2 - (A[d]+k)**2) diff2 = (A[c]**2 - max(0, (A[c]-k))**2) ans = ans1 - (diff1 + diff2) print(ans) #修正 A[d] += k A[c] = max(0, A[c]-k) ans1 = ans