#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:66777216")
using namespace std;
struct __isoff {
  __isoff() {
    if (0) freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    srand(time(0));
  }
  ~__isoff() {
    if (0) cerr << clock() * 1.0 / CLOCKS_PER_SEC << '\n';
  }
} __osafwf;
const unsigned long long p1 = 131797;
const unsigned long long p2 = 435493969;
const double eps = 1e-7;
const double pi = acos(-1.0);
const long long inf = 1e18 + 7;
const long long infi = 1e9 + 7;
const double infd = 23e30 + 7;
const long long dd = 1e5 + 7;
const long long mod = 1e9 + 7;
int n, m;
vector<pair<long long, pair<long long, long long> > > T, Q;
vector<pair<pair<long long, long long>, long long> > P;
set<pair<long long, long long> > E;
vector<long long> R;
int main() {
  cin >> m >> n;
  for (int i = 0; i < (int)n; i++) {
    int l, r, t;
    cin >> l >> r >> t;
    T.push_back(make_pair(t, make_pair(l, r)));
  }
  sort(T.begin(), T.end());
  for (int i = 0; i < (int)n; i++) {
    long long l = T[i].second.first, r = T[i].second.second, lf, rf;
    lf = l, rf = r;
    auto lt = E.upper_bound(make_pair(l, infi)),
         rt = E.upper_bound(make_pair(r, infi));
    if (rt != E.begin())
      rt--;
    else {
      Q.push_back(T[i]);
      E.insert(make_pair(l, r));
      continue;
    }
    if (lt == E.begin()) {
      Q.push_back(make_pair(T[i].first, make_pair(l, min(lt->first, r))));
      if (r < lt->first) {
        E.insert(make_pair(l, r));
        continue;
      }
      l = lt->second;
    } else {
      lt--;
      if (lt->second >= l) {
        l = lt->second;
        lf = lt->first;
      }
    }
    if (rt->second >= r) {
      r = rt->first;
      rf = rt->second;
      rt--;
    }
    while (l <= r) {
      if (l >= rt->first) {
        Q.push_back(make_pair(T[i].first, make_pair(l, r)));
      } else {
        Q.push_back(make_pair(T[i].first, make_pair(rt->second, r)));
      }
      r = rt->first;
      --rt;
    }
    lt = E.upper_bound(make_pair(lf, infi)),
    rt = E.upper_bound(make_pair(rf, infi));
    if (lt != E.begin()) {
      lt--;
      if (lt->second < lf) lt++;
    }
    E.erase(lt, rt);
    E.insert(make_pair(lf, rf));
  }
  n = Q.size();
  R.resize(m);
  for (int i = 0; i < (int)n; i++) {
    P.push_back(make_pair(
        make_pair(-(Q[i].second.first - Q[i].first), Q[i].second.first), 1));
    P.push_back(make_pair(
        make_pair(-(Q[i].second.second - Q[i].first), Q[i].second.second), -1));
  }
  for (int i = 0; i < (int)m; i++) {
    int t;
    cin >> t;
    P.push_back(make_pair(make_pair(t, i), 0));
  }
  sort(P.begin(), P.end());
  long long sumpl = 0, summi = 0, colpl = 0, colmi = 0;
  for (int i = 0; i < (int)P.size(); i++) {
    if (P[i].second == 1) {
      sumpl += P[i].first.first;
      colpl++;
    }
    if (P[i].second == -1) {
      summi += P[i].first.first;
      colmi++;
    }
    if (P[i].second == 0) {
      R[P[i].first.second] = -(P[i].first.first * colpl - sumpl) -
                             (summi - P[i].first.first * colmi);
    }
  }
  for (int i = 0; i < (int)m; i++) cout << R[i] << '\n';
}
