// clang-format off #include using namespace std; using ll = long long; using ld = long double; template using V = vector; using VI = V; using VL = V; using VS = V; template using PQ = priority_queue, greater>; using G = V; template using WG = V>>; #define overload4(_1,_2,_3,_4,name,...) name #define rep1(n) for(ll i=0;i<(n);++i) #define rep2(i,n) for(ll i=0;i<(n);++i) #define rep3(i,a,b) for(ll i=(a);i<(b);++i) #define rep4(i,a,b,c) for(ll i=(a);i<(b);i+=(c)) #define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__) #define rrep1(n) for(ll i=n;i>0;--i) #define rrep2(i,n) for(ll i=n;i>0;--i) #define rrep3(i,a,b) for(ll i=b;i>a;--i) #define rrep4(i,a,b,c) for(ll i=(a)+((b)-(a)-1)/(c)*(c);i>=(a);i-=c) #define rrep(...) overload4(__VA_ARGS__,rrep4,rrep3,rrep2,rrep1)(__VA_ARGS__) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define inside(h,w,y,x) (unsigned(y) inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; } template inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; } inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } template inline istream& operator>>(istream& is, V& v) { for (auto& a : v)is >> a; return is; } template inline istream& operator>>(istream& is, pair& p) { is >> p.first >> p.second; return is; } template inline V vec(size_t a) { return V(a); } template inline V defvec(T def, size_t a) { return V(a, def); } template inline auto vec(size_t a, Ts... ts) { return V(ts...))>(a, vec(ts...)); } template inline auto defvec(T def, size_t a, Ts... ts) { return V(def, ts...))>(a, defvec(def, ts...)); } template inline void print(const T& a) { cout << a << "\n"; } template inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); } template inline void print(const V& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); } template inline void print(const V>& v) { for (auto& a : v)print(a); } template inline constexpr const T cum(const V& a, int l, int r) { return 0 <= l && l <= r && r < a.size() ? a[r] - (l == 0 ? 0 : a[l - 1]) : 0; }//[l,r] template inline constexpr const auto min(const T& v) { return *min_element(all(v)); } template inline constexpr const auto max(const T& v) { return *max_element(all(v)); } template inline V& operator++(V& v) { for (T& a : v)++a; return v; } template inline V& operator--(V& v) { for (T& a : v)--a; return v; } // clang-format on template class compress { vector xs; public: compress() {} compress(const vector& vs) { add(vs); } inline void add(const vector& vs) { copy(all(vs), back_inserter(xs)); } inline void add(const T& x) { xs.emplace_back(x); } inline void build() { sort(all(xs)); xs.erase(unique(all(xs)), xs.end()); } inline int idx(const T& x) const { return lower_bound(all(xs), x) - xs.begin(); } inline T operator[](int k) const { return xs[k]; } inline int size() const { return xs.size(); } }; template class BinaryIndexedTree { int n; vector dat; public: BinaryIndexedTree(int n) : n(n), dat(n + 1){}; BinaryIndexedTree(int n, T a) : n(n), dat(n + 1) { for (int i = 1; i <= n; ++i) { dat[i] += a; if (i + (i & -i) <= n) dat[i + (i & -i)] += dat[i]; } } BinaryIndexedTree(V v) : n(v.size()), dat(n + 1) { for (int i = 1; i <= n; ++i) { dat[i] += v[i - 1]; if (i + (i & -i) <= n) dat[i + (i & -i)] += dat[i]; } } void add(int i, T a) { for (++i; i <= n; i += i & -i) dat[i] += a; } T sum(int r) { // sum of [0,r) T res = 0; for (; r; r -= r & -r) res += dat[r]; return res; } T sum(int l, int r) { // sum of [l,r) if (l < 0 || n < r || l > r) return 0; return sum(r) - sum(l); } int lower_bound(T a) { int res = 0, k = 1; while (k * 2 <= n) k *= 2; for (; k; k /= 2) { if (res + k <= n && a > dat[res + k]) { a -= dat[res + k]; res += k; } } return res; } }; int main() { init(); int n, q; cin >> n >> q; VL a(n); cin >> a; VL ans(q); V> task; // x(lr)i rep(i, n) task.emplace_back(a[i], 0, i, 0); rep(i, q) { int l, r; ll x; cin >> l >> r >> x; ans[i] += (r - l + 1) * x; task.emplace_back(x, l - 1, i, -1); task.emplace_back(x, r, i, +1); } sort(all(task)); BinaryIndexedTree bit(n), cnt(n); for (auto [x, r, i, p] : task) { if (p == 0) { bit.add(i, x); cnt.add(i, 1); } else { ans[i] += bit.sum(r) * p; ans[i] += cnt.sum(r) * x * p * -1; } } for (auto x : ans) print(x); return 0; }