#include #include using namespace std; using namespace atcoder; typedef long long ll; typedef pair P; ll op(ll a, ll b) { return a + b; } ll e() { return 0; } int main() { int n, q; cin >> n >> q; int a[100005]; P z[100005]; for(int i = 0; i < n; i++) { cin >> a[i]; z[i] = P(a[i], i); } int l[100005], r[100005], x[100005]; P p[100005]; for(int i = 0; i < q; i++) { cin >> l[i] >> r[i] >> x[i]; l[i]--; p[i] = P(x[i], i); } sort(p, p + n); segtree sum(n), cnt(n); for(int i = 0; i < n; i++) { cnt.set(i, 1); } ll ans[100005]; int u = 0; for(int t = 0; t < q; t++) { int i = p[t].second; while(u < n && z[u].first <= x[i]) { int j = z[u++].second; sum.set(j, a[j]); cnt.set(j, 0); } ans[i] = sum.prod(l[i], r[i]) + x[i] * cnt.prod(l[i], r[i]); } for(int i = 0; i < q; i++) { cout << ans[i] << endl; } }