func_code_string: #include <bits/stdc++.h>   using namespace std;   const int maxN = 100010;   int n, m, res, l[3][maxN], r[3][maxN], g[16 * maxN], t[16 * maxN], ans[maxN],       con[maxN];   bool avail[maxN];   stack<int> s[4 * maxN];   struct ioi {     int v, p, t, k;   };   ioi c[4 * maxN];   bool cmp(ioi i, ioi j) {     if (i.v < j.v) return true;     if (i.v > j.v) return false;     if (i.t < j.t) return true;     if (i.t > j.t) return false;     if (i.t == 1)       return (i.k > j.k);     else       return (i.k < j.k);   }   void update(int k, int l, int r, int i, int x) {     if ((i < l) || (i > r)) return;     if (l == r) {       t[k] += x;       if (t[k])         g[k] = l;       else         g[k] = 0;       return;     }     int mid = (l + r) >> 1;     update(k * 2, l, mid, i, x);     update(k * 2 + 1, mid + 1, r, i, x);     t[k] = t[k * 2] + t[k * 2 + 1];     if (g[k * 2] == 0)       g[k] = g[k * 2 + 1];     else if (g[k * 2 + 1] == 0)       g[k] = g[k * 2];     else       g[k] = min(g[k * 2], g[k * 2 + 1]);   }   int get(int k, int l, int r, int i) {     if (r < i) return 0;     if (l >= i) return g[k];     if (l == r) return 0;     int mid = (l + r) >> 1;     int tmp_1 = get(k * 2, l, mid, i);     int tmp_2 = get(k * 2 + 1, mid + 1, r, i);     if (!tmp_1) return tmp_2;     if (!tmp_2) return tmp_1;     return min(tmp_1, tmp_2);   }   int main() {     scanf( %d , &n);     int x, y, z, num = 0;     for (int i = 1; i <= n; ++i) {       scanf( %d%d , &x, &y);       l[1][i] = x;       r[1][i] = y;       c[++num].v = x;       c[num].t = 1;       c[num].k = 1;       c[num].p = i;       c[++num].v = y;       c[num].t = 2;       c[num].k = 1;       c[num].p = i;     }     scanf( %d , &m);     for (int i = 1; i <= m; ++i) {       scanf( %d%d%d , &x, &y, &z);       l[2][i] = x;       r[2][i] = y;       con[i] = z;       c[++num].v = x;       c[num].t = 1;       c[num].k = 2;       c[num].p = i;       c[++num].v = y;       c[num].t = 2;       c[num].k = 2;       c[num].p = i;     }     sort(c + 1, c + num + 1, cmp);     int val = c[1].v;     c[1].v = 1;     for (int i = 2; i <= num; ++i) {       int tmp_val = c[i].v;       if (c[i].v != val)         c[i].v = c[i - 1].v + 1;       else         c[i].v = c[i - 1].v;       if (c[i].t == 1)         l[c[i].k][c[i].p] = c[i].v;       else         r[c[i].k][c[i].p] = c[i].v;       val = tmp_val;     }     for (int i = 1; i <= num; ++i) {       if (c[i].k == 1) {         if (c[i].t == 1) {           int u = get(1, 1, c[num].v, r[1][c[i].p]);           if (u == 0) {             res = -1;             break;           }           while ((!s[u].empty()) && (!avail[s[u].top()])) s[u].pop();           if (u == 0) {             res = -1;             break;           }           u = s[u].top();           ans[c[i].p] = u;           con[u]--;           if (!con[u]) update(1, 1, c[num].v, r[2][u], -1), avail[u] = 0;         }       } else if (c[i].t == 1) {         update(1, 1, c[num].v, r[2][c[i].p], 1);         s[r[2][c[i].p]].push(c[i].p);         avail[c[i].p] = 1;       } else {         update(1, 1, c[num].v, c[i].v, -1);         avail[c[i].p] = 0;       }     }     if (res == -1)       printf( NO );     else {       printf( YES n );       for (int i = 1; i <= n; ++i) printf( %d  , ans[i]);     }     fclose(stdin);     fclose(stdout);   }   