#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;
using ll = long long;

template <typename T>
map<T, T> compress(vector<T> &A){

    map<T, T> comp;
    int N = A.size(), i=0;
    for (int i=0; i<N; i++) comp[A[i]];

    for (auto &e : comp){
        e.second = i;
        i++;
    }

    return comp;
}

template<class T> struct BIT {
    vector<T> bit;
    long long N;
    T P;

    BIT (long long n, T p = 0){
        N = n;
        P = p;
        bit.resize(N);
    }

    void add(long long loc, T val){
        loc++;
        while(loc <= N){
            bit[loc-1] += val;
            if (P) bit[loc-1] %= P;
            loc += loc & -loc;
        }
    }

    long long sum(long long l, long long r){
        T res = _sum(r) - _sum(l-1);
        if (P) res = (res + P) % P;
        return res;
    }

    long long _sum(long long r){
        r++;
        T res = 0;
        while(r > 0){
            res += bit[r-1];
            if (P) res %= P;
            r -= r & -r;
        }
        return res;
    }
};


int main(){

    ll N, Q, L, R, X, now=0;
    cin >> N >> Q;
    vector<ll> v, A(N), ans(2*Q);
    vector<tuple<ll, ll, ll>> RXM(2*Q);
    BIT<ll> tc(3e5+5), ts(3e5+5);

    for (int i=0; i<N; i++){
        cin >> A[i];
        v.push_back(A[i]);
    }
    for (int i=0; i<Q; i++){
        cin >> L >> R >> X; L--; R--;
        v.push_back(X);
        RXM[i*2] = {L-1, X, i*2};
        RXM[i*2+1] = {R, X, i*2+1};
    }
    sort(RXM.begin(), RXM.end());

    map<ll, ll> mp = compress(v);

    for (auto [R, X, M] : RXM){
        while(now <= R){
            tc.add(mp[A[now]], 1);
            ts.add(mp[A[now]], A[now]);
            now++;
        }
        ans[M] = ts.sum(0, mp[X]-1) +  tc.sum(mp[X], 3e5+4) * X;
    }

    for (int i=0; i<Q; i++) cout << ans[i*2+1] - ans[i*2] << endl;

    return 0;
}