#include using namespace std; template struct BinaryIndexedTree { int N; vectorbit; BinaryIndexedTree(){} BinaryIndexedTree(int x) { N = x; bit.resize(x+1); } void add(int x,T y) { x++; while(x <= N) { bit[x] += y; x += x&-x; } } T sum(int x) { x++; T res = 0; while(x) { res += bit[x]; x -= x&-x; } return res; } inline T sum(int l, int r) {//[l,r) return sum(r-1)-sum(l-1); } inline T operator[](int k) { return sum(k)-sum(k-1); } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vectorL(N),R(N),a(N),cmp; for(int i = 0; i < N; i++) { cin >> L[i] >> R[i] >> a[i]; cmp.push_back(L[i]); cmp.push_back(R[i]+1); } int Q; cin >> Q; vectorx(Q); for(int i = 0; i < Q; i++) { cin >> x[i]; cmp.push_back(x[i]); } sort(cmp.begin(),cmp.end()); cmp.erase(unique(cmp.begin(),cmp.end()),cmp.end()); for(int i = 0; i < N; i++) { L[i] = lower_bound(cmp.begin(),cmp.end(),L[i])-cmp.begin(); R[i] = lower_bound(cmp.begin(),cmp.end(),R[i]+1)-cmp.begin(); } for(int i = 0; i < Q; i++) { x[i] = lower_bound(cmp.begin(),cmp.end(),x[i])-cmp.begin(); } map>>mp; for(int i = 0; i < N; i++) { mp[a[i]].push_back({L[i],R[i]}); } map>>mp2; for(auto i:mp) { vector>tmp = i.second; sort(tmp.begin(),tmp.end()); vector>res; int mi = -1,mx = -1; for(int k = 0; k < tmp.size(); k++) { if(mx == -1) { mi = tmp[k].first; mx = tmp[k].second; } else if(mx <= tmp[k].first) { res.push_back({mi,mx}); mi = tmp[k].first; mx = tmp[k].second; } else { mx = max(mx,tmp[k].second); } } res.push_back({mi,mx}); mp2[i.first] = res; } vectorl(Q),r(Q,N+3); while(true) { bool flag = false; for(int i = 0; i < Q; i++) { if(l[i]+1 < r[i]) { flag = true; } } if(!flag) break; map>>mp3 = mp2; for(int i = 0; i < Q; i++) { if(l[i]+1 < r[i]) { int mid = (l[i]+r[i])/2; mp3[mid].push_back({i,-1}); } } BinaryIndexedTreebit(cmp.size()); for(auto i:mp3) { for(auto k:i.second) { if(k.second == -1) { if(bit.sum(x[k.first]) == i.first) { l[k.first] = i.first; } else { r[k.first] = i.first; } } } for(auto k:i.second) { if(k.second == -1) continue; bit.add(k.first,1); bit.add(k.second,-1); } } } for(int i = 0; i < Q; i++) { cout << l[i] << "\n"; } }