#include // clang-format off using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair; const ll INF=4e18; void print0(){}; template void print0(H h,T... t){cout<void print(H h,T... t){print0(h);if(sizeof...(T)>0)print0(" ");print(t...);} void perr0(){}; template void perr0(H h,T... t){cerr<void perr(H h,T... t){perr0(h);if(sizeof...(T)>0)perr0(" ");perr(t...);} void ioinit() { cout< data; SGT default_value; segment_tree(ll n) { default_value = get_default_value(); ll siz = 1; while (siz < n) { siz = siz * 2; } data.resize(siz * 2, default_value); size = siz; } ~segment_tree() {} //---------------------------- SGT compare(SGT& a, SGT& b) { return a + b; } SGT get_default_value() { return 0; } //---------------------------- void update(ll k, SGT value) { k += size - 1; data[k] = value; while (k > 0) { k = (k - 1) / 2; data[k] = compare(data[k * 2 + 1], data[k * 2 + 2]); } } SGT query_open(ll a, ll b, ll k, ll l, ll r) { if (r <= a || b <= l) { return default_value; } if (a <= l && r <= b) { return data[k]; } SGT vl = query_open(a, b, k * 2 + 1, l, (l + r) / 2); SGT vr = query_open(a, b, k * 2 + 2, (l + r) / 2, r); return compare(vl, vr); } SGT query(ll a, ll b) { return query_open(a, b + 1, 0, 0, size); } }; using liii = tuple; using pli = pair; int main() { // Xの大きい順 ioinit(); int N, Q; cin >> N >> Q; vector A(N); rep(i, N) { cin >> A[i]; } vector B(N); rep(i, N) { B[i] = {A[i], i}; } sort(B.rbegin(), B.rend()); vector queries; rep(i, Q) { int l, r; ll x; cin >> l >> r >> x; l--; r--; queries.push_back({x, l, r, i}); } sort(queries.rbegin(), queries.rend()); auto sumseg = segment_tree(N); auto lgseg = segment_tree(N); rep(i, N) { sumseg.update(i, A[i]); } vector ans(Q); int bi = 0; for (auto que : queries) { ll x; int l, r, qid; tie(x, l, r, qid) = que; while (bi < N && x < B[bi].first) { int j = B[bi].second; lgseg.update(j, 1); sumseg.update(j, 0); bi++; } ans[qid] = sumseg.query(l, r) + x * lgseg.query(l, r); } rep(i, Q) { print(ans[i]); } return 0; }