func_code_string: #include <bits/stdc++.h>   using namespace std;   struct Wall {     int l, r, t;     void init(int _l, int _r, int _t) { l = _l, r = _r, t = _t; }     void input() { scanf( %d%d%d , &l, &r, &t); }     static bool by_l(const Wall &a, const Wall &b) { return a.l < b.l; }     bool operator<(const Wall &a) const { return t > a.t; }   } w[500010], wc[500010];   struct Table {     int a[500010 * 2], top;     Table() { top = 0; }     void insert(int x) { a[top++] = x; }     void sort() {       std::sort(a, a + top);       top = unique(a, a + top) - a;     }     int search(int x) { return lower_bound(a, a + top, x) - a; }   } table;   struct Tri {     int x, p;     void init(int _x, int _p) { x = _x, p = _p; }     bool operator<(const Tri &a) const { return x < a.x; }   } tri[500010];   int q[500010];   int main() {     int n, m;     cin >> m >> n;     for (int i = 0; i < n; ++i) {       w[i].input();     }     for (int i = 0; i < m; ++i) {       scanf( %d , q + i);     }     sort(w, w + n, Wall::by_l);     for (int i = 0; i < n; ++i) {       table.insert(w[i].l), table.insert(w[i].r);     }     table.sort();     priority_queue<Wall> que;     int nc = 0;     for (int i = 0, j = 0; i < table.top - 1; ++i) {       while (j < n && w[j].l <= table.a[i]) {         que.push(w[j++]);       }       while (!que.empty()) {         Wall wall = que.top();         if (wall.r > table.a[i]) {           wc[nc++].init(table.a[i], table.a[i + 1], wall.t);           break;         }         que.pop();       }     }     int ntri = 0;     for (int i = 0; i < nc; ++i) {       tri[ntri++].init(wc[i].t - wc[i].r, 1);       tri[ntri++].init(wc[i].t - wc[i].l, -1);     }     sort(tri, tri + ntri);     int sgm = 0, cnt = 0;     for (int i = 0, j = 0; i < m; ++i) {       while (j < ntri && tri[j].x <= q[i]) {         cnt += tri[j].p;         sgm += tri[j].x * tri[j].p;         ++j;       }       printf( %d n , q[i] * cnt - sgm);     }     return 0;   }   