#include #include int cmp_int (const void *ap, const void *bp) { int a = *(int *)ap; int b = *(int *)bp; if (a < b) { return -1; } if (a > b) { return 1; } return 0; } void eval (int *t, int lazy[][2], int k, int l, int r) { if (lazy[k][0] <= 0) { return; } t[k] = lazy[k][0]; if (r-l > 1) { if (t[2*k+1] >= lazy[k][1]-1 || lazy[2*k+1][0] >= lazy[k][1]-1) { lazy[2*k+1][0] = lazy[k][0]; if (lazy[2*k+1][1] <= 0) { lazy[2*k+1][1] = lazy[k][1]; } } if (t[2*k+2] >= lazy[k][1]-1 || lazy[2*k+2][0] >= lazy[k][1]-1) { lazy[2*k+2][0] = lazy[k][0]; if (lazy[2*k+2][1] <= 0) { lazy[2*k+2][1] = lazy[k][1]; } } } lazy[k][0] = 0; lazy[k][1] = 0; return; } void set_segt_rec (int *t, int lazy[][2], int a, int b, int val, int k, int l, int r) { eval(t, lazy, k, l, r); if (r <= a || b <= l) { return; } if (a <= l && r <= b) { if (t[k] >= val-1) { lazy[k][0] = val; lazy[k][1] = val; eval(t, lazy, k, l, r); } return; } set_segt_rec(t, lazy, a, b, val, 2*k+1, l, (l+r)/2); set_segt_rec(t, lazy, a, b, val, 2*k+2, (l+r)/2, r); t[k] = t[2*k+1]; if (t[k] < t[2*k+2]) { t[k] = t[2*k+2]; } return; } void set_segt (int *t, int lazy[][2], int a, int b, int val, int size) { set_segt_rec(t, lazy, a, b, val, 0, 0, size); return; } int max_segt_rec (int *t, int lazy[][2], int a, int b, int k, int l, int r) { int ans = 0; int tmp = 0; if (r <= a || b <= l) { return 0; } eval(t, lazy, k, l, r); if (a <= l && r <= b) { return t[k]; } ans = max_segt_rec(t, lazy, a, b, 2*k+1, l, (l+r)/2); tmp = max_segt_rec(t, lazy, a, b, 2*k+2, (l+r)/2, r); if (ans < tmp) { ans = tmp; } return ans; } int max_segt (int *t, int lazy[][2], int a, int b, int size) { return max_segt_rec(t, lazy, a, b, 0, 0, size); } int main () { int n = 0; int l[100000] = {}; int r[100000] = {}; int a[100000][2] = {}; int q = 0; int x[100000] = {}; int res = 0; int map[300000] = {}; int cnt = 0; int uniq_cnt = 1; int t[1200000] = {}; int lazy[1200000][2] = {}; int size = 1; res = scanf("%d", &n); for (int i = 0; i < n; i++) { res = scanf("%d", l+i); res = scanf("%d", r+i); res = scanf("%d", a[i]); map[cnt] = l[i]; cnt++; map[cnt] = r[i]; cnt++; a[i][1] = i; } res = scanf("%d", &q); for (int i = 0; i < q; i++) { res = scanf("%d", x+i); map[cnt] = x[i]; cnt++; } qsort(map, cnt, sizeof(int), cmp_int); for (int i = 1; i < cnt; i++) { if (map[i-1] != map[i]) { map[uniq_cnt] = map[i]; uniq_cnt++; } } while (size <= uniq_cnt) { size <<= 1; } qsort(a, n, sizeof(int)*2, cmp_int); for (int i = 0; i < n; i++) { int lidx[2] = { 0, uniq_cnt }; int ridx[2] = { 0, uniq_cnt }; while (lidx[1]-lidx[0] > 1) { int nxt = (lidx[0]+lidx[1])/2; if (map[nxt] <= l[a[i][1]]) { lidx[0] = nxt; } else { lidx[1] = nxt; } } while (ridx[1]-ridx[0] > 1) { int nxt = (ridx[0]+ridx[1])/2; if (map[nxt] <= r[a[i][1]]) { ridx[0] = nxt; } else { ridx[1] = nxt; } } set_segt(t, lazy, lidx[0], ridx[1], a[i][0]+1, size); } for (int i = 0; i < q; i++) { int idx[2] = { 0, uniq_cnt }; while (idx[1]-idx[0] > 1) { int nxt = (idx[0]+idx[1])/2; if (map[nxt] <= x[i]) { idx[0] = nxt; } else { idx[1] = nxt; } } printf("%d\n", max_segt(t, lazy, idx[0], idx[1], size)); } return 0; }