#include #include #include #include using namespace std; using ll = long long; using P = pair; template vector compress(vector &x){ vector vals = x; sort(vals.begin(), vals.end()); vals.erase(unique(vals.begin(), vals.end()), vals.end()); for(auto &p: x){ p = lower_bound(vals.begin(), vals.end(), p) - vals.begin(); } return vals; } struct event{ int id; int op; int val; event(int i, int o, int v): id(i), op(o), val(v){} }; int main(){ int n; cin >> n; vector l(n), r(n), a(n); for(int i = 0; i < n; i++){ cin >> l[i] >> r[i] >> a[i]; } int q; cin >> q; vector x(q); for(auto &it: x) cin >> it; for(int i = 0; i < n; i++){ a.emplace_back(a[i]+1); a.emplace_back(a[i]-1); } a.emplace_back(0); a.emplace_back(-1); vector avals = compress(a); vector events; for(int i = 0; i < n; i++){ events.emplace_back(l[i], 0, a[i]); events.emplace_back(r[i], 2, a[i]); } vector xvals = compress(x); for(int i = 0; i < q; i++) events.emplace_back(xvals[x[i]], 1, x[i]); sort(events.begin(), events.end(), [](auto &s, auto &t){ if(s.id != t.id) return s.id < t.id; else return s.op < t.op; }); set mem; for(int i = 1; i < avals.size(); i++){ mem.emplace(i); } vector ans(q, -1); vector cnt(avals.size(), 0); for(auto &it: events){ if(it.op == 0){ cnt[it.val]++; if(cnt[it.val] == 1) mem.erase(it.val); }else if(it.op == 2){ cnt[it.val]--; if(cnt[it.val] == 0) mem.emplace(it.val); }else{ // cerr << it.val << " " << it.id << " " << *mem.begin() << endl; ans[it.val] = avals[*mem.begin()]; } } for(int i = 0; i < q; i++) cout << ans[i] << '\n'; return 0; }