using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var n = NN; var map = NArr(n); var q = NN; var a = NList; var set = new HashSet(); set.Add(1); set.Add(1_000_000_001); for (var i = 0; i < n; ++i) { set.Add(map[i][0]); set.Add(map[i][1] + 1); } foreach (var ai in a) set.Add(ai); var list = new List(set); list.Sort(); var dic = new Dictionary(); for (var i = 0; i < list.Count; ++i) dic[list[i]] = i; var rlist = new List<(int l, int r)>[n + 1]; for (var i = 0; i < rlist.Length; ++i) rlist[i] = new List<(int l, int r)>(); for (var i = 0; i < n; ++i) if (map[i][2] < rlist.Length) { rlist[map[i][2]].Add((map[i][0], map[i][1] + 1)); } for (var i = 0; i < rlist.Length; ++i) { if (rlist[i].Count == 0) { rlist[i] = new List<(int l, int r)>{ (1, 1_000_000_001) }; continue; } rlist[i].Sort((l, r) => { var d = l.l.CompareTo(r.l); if (d != 0) return d; return l.r.CompareTo(r.r); }); // WriteLine($"rlist[{i}]: {string.Join(" ", rlist[i])}"); var nlist = new List<(int l, int r)>(); nlist.Add(rlist[i][0]); for (var j = 1; j < rlist[i].Count; ++j) { var prev = nlist[^1]; if (prev.r >= rlist[i][j].l) { nlist[^1] = (prev.l, rlist[i][j].r); } else { nlist.Add(rlist[i][j]); } } // WriteLine($"nlist[{i}]: {string.Join(" ", nlist)}"); var exlist = new List<(int l, int r)>(); if (1 < nlist[0].l) exlist.Add((1, nlist[0].l)); for (var j = 1; j < nlist.Count; ++j) exlist.Add((nlist[j - 1].r, nlist[j].l)); if (nlist[^1].r < 1_000_000_001) exlist.Add((nlist[^1].r, 1_000_000_001)); rlist[i] = exlist; } var seg = new LazySegTree(list.Count, new Op()); for (var i = n; i >= 0; --i) { foreach (var ex in rlist[i]) { seg.Apply(dic[ex.l], dic[ex.r], i); // WriteLine($"seg[{dic[ex.l]}..{dic[ex.r]}] = {i}"); // for (var j = 0; j < list.Count; ++j) Write(seg.Get(j) + " "); // WriteLine(); } } var ans = new int[q]; for (var i = 0; i < q; ++i) ans[i] = seg.Get(dic[a[i]]); WriteLine(string.Join("\n", ans)); } class Op : ILazySegTreeOperator { public int Composition(int f, int g) { return f == Id() ? g : f; } public int E() { return int.MaxValue; } public int Id() { return int.MaxValue; } public int Mapping(int f, int x) { return f == Id() ? x : f; } int ILazySegTreeOperator.Op(int a, int b) { return Math.Min(a, b); } } interface ILazySegTreeOperator { /// 集合S上の二項演算 S×S → S S Op(S a, S b); /// Sの単位元 S E(); /// 写像f(x) ※更新、加算などの処理 S Mapping(F f, S x); /// 写像の合成 f ○ g ※後に行う操作がfとなる( F Composition(F f, F g); /// 恒等写像 id F Id(); } // モノイドの型 S // 写像の型 F // 以下の関数を格納する T // ・: S × S → S を計算する関数 S op(S a, S b) // e を返す関数 S e() // f(x) を返す関数 S mapping(F f, S x) // f○gを返す関数 F composition(F f, F g) // idを返す関数 F id() // S,Fはreadonlyにしておくと速い // Tの関数オーバーフローに注意 class LazySegTree { int _n; int size; int log; List d; List lz; ILazySegTreeOperator op; public LazySegTree(int n, ILazySegTreeOperator op) { _n = n; var v = new S[n]; for (var i = 0; i < v.Length; ++i) v[i] = op.E(); Init(v, op); } public LazySegTree(S[] v, ILazySegTreeOperator op) { _n = v.Length; Init(v, op); } private void Init(S[] v, ILazySegTreeOperator op) { size = 1; log = 0; this.op = op; while (size < v.Length) { size <<= 1; ++log; } d = Enumerable.Repeat(op.E(), size * 2).ToList(); lz = Enumerable.Repeat(op.Id(), size).ToList(); for (var i = 0; i < v.Length; ++i) d[size + i] = v[i]; for (var i = size - 1; i >= 1; --i) Update(i); } /// 一点更新 public void Set(int pos, S x) { pos += size; for (var i = log; i >= 1; --i) Push(pos >> i); d[pos] = x; for (var i = 1; i <= log; ++i) Update(pos >> i); } /// 一点取得 public S Get(int pos) { pos += size; for (var i = log; i >= 1; --i) Push(pos >> i); return d[pos]; } /// 区間取得 op(a[l..r-1]) public S Prod(int l, int r) { if (l == r) return op.E(); l += size; r += size; for (var i = log; i >= 1; --i) { if (((l >> i) << i) != l) Push(l >> i); if (((r >> i) << i) != r) Push(r >> i); } S sml = op.E(); S smr = op.E(); while (l < r) { if ((l & 1) != 0) sml = op.Op(sml, d[l++]); if ((r & 1) != 0) smr = op.Op(d[--r], smr); l >>= 1; r >>= 1; } return op.Op(sml, smr); } /// 全体取得 op(a[0..n-1]) public S AllProd() => d[1]; /// なにこれ a[p] = op_st(a[p], x) public void Apply(int pos, F f) { pos += size; for (var i = log; i >= 1; --i) Push(pos >> i); d[pos] = op.Mapping(f, d[pos]); for (var i = 1; i <= log; ++i) Update(pos >> i); } /// 区間更新 i = l..r-1 について a[i] = op_st(a[i], x) public void Apply(int l, int r, F f) { if (l == r) return; l += size; r += size; for (var i = log; i >= 1; --i) { if (((l >> i) << i) != l) Push(l >> i); if (((r >> i) << i) != r) Push((r - 1) >> i); } { var l2 = l; var r2 = r; while (l < r) { if ((l & 1) != 0) AllApply(l++, f); if ((r & 1) != 0) AllApply(--r, f); l >>= 1; r >>= 1; } l = l2; r = r2; } for (var i = 1; i <= log; ++i) { if (((l >> i) << i) != l) Update(l >> i); if (((r >> i) << i) != r) Update((r - 1) >> i); } } void Update(int k) { d[k] = op.Op(d[2 * k], d[2 * k + 1]); } void AllApply(int k, F f) { d[k] = op.Mapping(f, d[k]); if (k < size) lz[k] = op.Composition(f, lz[k]); } void Push(int k) { AllApply(2 * k, lz[k]); AllApply(2 * k + 1, lz[k]); lz[k] = op.Id(); } } }