class Fenwick_Tree: def __init__(self, n): self.n = n self.data = [0] * n def add(self, p, x): p += 1 while p <= self.n: self.data[p - 1] += x p += p & -p def sum(self, l, r): '''範囲[l, r)(lからr-1まで)の総和を求める''' return self._sum(r) - self._sum(l) def _sum(self, r): '''範囲[0, r)(0からr-1まで)の総和を求める''' s = 0 while r > 0: s += self.data[r - 1] r -= r & -r return s n, q = map(int, input().split()) A = list(map(int, input().split())) NI = [(A[i], i) for i in range(n)] Q = [] for i in range(q): l, r, x = map(int, input().split()) Q.append((l - 1, r)) NI.append((x, n + i)) NI.sort(key=lambda x: (x[0], x[1])) ANS = [0 for _ in range(q)] SumNFT = Fenwick_Tree(n) SumIFT = Fenwick_Tree(n) for i in range(n + q): x, idx = NI[i] if idx < n: SumNFT.add(idx, x) SumIFT.add(idx, 1) else: idx -= n l, r = Q[idx] x_idx_num = r - l - SumIFT.sum(l, r) ANS[idx] = SumNFT.sum(l, r) + x * x_idx_num print(*ANS, sep='\n')