#include using namespace std; using ll=long long; #define rep(i,n) for(int i=0;i=0;i--) #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() template bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;} template bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;} template struct RangeMex { const T inf = numeric_limits::max(); set> se; RangeMex() { se.insert(make_pair(-inf, -inf)); se.insert(make_pair(inf, inf)); } void add(T x) { auto id1 = se.lower_bound(make_pair(x + 1, x + 1)); auto id2 = se.lower_bound(make_pair(x, x)); id2--; pair p1 = *id1, p2 = *id2; if (p1.first > x + 1 && p2.second < x - 1) { se.insert(make_pair(x, x)); } else if (p1.first > x + 1) { se.insert(make_pair(p2.first, x)); se.erase(p2); } else if (p2.second < x - 1) { se.insert(make_pair(x, p1.second)); se.erase(p1); } else { se.insert(make_pair(p2.first, p1.second)); se.erase(p1); se.erase(p2); } } void erase(T x) { auto id = se.lower_bound(make_pair(x + 1, x + 1)); id--; pair p = *id; if (p.second < x) return; if (p.first <= x - 1) se.insert(make_pair(p.first, x - 1)); if (x + 1 <= p.second) se.insert(make_pair(x + 1, p.second)); se.erase(p); } T mex(int l, int r) { //[l,r)のmex --r; auto id = se.lower_bound(make_pair(l, l)); pair p = *id; if (p.first != l) { id--; pair p2 = *id; if (p2.second < l) return l; else if (p2.second < r) return p2.second + 1; else return -1; } else if (p.second < r) return p.second + 1; else return -1; } }; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin>>n; vector>T; vectorA(n); rep(i,n){ int l,r; cin>>l>>r>>A[i]; T.push_back(make_tuple(l,-1,i)); T.push_back(make_tuple(r,1,i)); } int q; cin>>q; rep(i,q){ int x; cin>>x; T.push_back(make_tuple(x,0,i)); } sort(all(T)); vectorans(q); RangeMexM; mapmp; int mex=0; for(auto[x,t,i]:T){ if(t==0){ ans[i]=M.mex(0,1<<30); }else if(t==-1){ if(!mp.count(A[i]))M.add(A[i]); mp[A[i]]++; }else{ mp[A[i]]--; if(mp[A[i]]==0){ mp.erase(A[i]); M.erase(A[i]); } } } rep(i,q)cout<