#include using namespace std; template struct invertible_binary_indexed_tree{ int N; vector BIT; function f; function inv; T E; invertible_binary_indexed_tree(){ } invertible_binary_indexed_tree(int N, function f, function inv, T E): N(N), BIT(N + 1, E), f(f), inv(inv), E(E){ } invertible_binary_indexed_tree(const vector &A, function f, function inv, T E): N(A.size()), BIT(N + 1), f(f), inv(inv), E(E){ for (int i = 0; i < N; i++){ BIT[i + 1] = A[i]; } for (int i = 1; i < N; i++){ if (i + (i & -i) <= N){ BIT[i + (i & -i)] = f(BIT[i + (i & -i)], BIT[i]); } } } void add(int i, T x){ i++; while (i <= N){ BIT[i] = f(BIT[i], x); i += i & -i; } } T sum(int i){ T ans = E; while (i > 0){ ans = f(ans, BIT[i]); i -= i & -i; } return ans; } T sum(int l, int r){ return f(sum(r), inv(sum(l))); } }; int main(){ int N, Q; cin >> N >> Q; vector A(N); for (int i = 0; i < N; i++){ cin >> A[i]; } vector L(Q), R(Q), X(Q); for (int i = 0; i < Q; i++){ cin >> L[i] >> R[i] >> X[i]; L[i]--; } invertible_binary_indexed_tree BIT1(A, plus(), negate(), 0); invertible_binary_indexed_tree BIT2(N, plus(), negate(), 0); vector> query; for (int i = 0; i < N; i++){ query.push_back(make_tuple(A[i], 0, i)); } for (int i = 0; i < Q; i++){ query.push_back(make_tuple(X[i], 1, i)); } sort(query.begin(), query.end(), greater>()); vector ans(Q); for (int i = 0; i < N + Q; i++){ int t = get<1>(query[i]); int p = get<2>(query[i]); if (t == 0){ BIT1.add(p, -A[p]); BIT2.add(p, 1); } if (t == 1){ ans[p] = BIT1.sum(L[p], R[p]) + (long long) X[p] * BIT2.sum(L[p], R[p]); } } for (int i = 0; i < Q; i++){ cout << ans[i] << endl; } }