#include #define REP(i,n) for(int i=0,i##_len=int(n);i> &ranges) { // rangesは昇順データ vector> nxt_range; for(const auto &range: ranges) { if(nxt_range.size() == 0){ nxt_range.push_back(range); } else { pair &fr = nxt_range.back(); if(range.first <= fr.second + 1) { fr.second = max(fr.second, range.second); } else { nxt_range.push_back(range); } } } ranges = nxt_range; } int main(){ int n;cin>>n; vector>> op(n); REP(i,n){ int l, r,a; cin>>l>>r>>a; op[i] = {a, {l, r}}; } sort(All(op)); // 数iを含む区間[l,r]の範囲 vector>> dp(n); int mx = 0; int Lidx = 0; for(auto p:op){ int a = p.first; pair range = p.second; if(a >= n) { // どうせn以上のaは意味がない break; } else{ dp[a].push_back(range); } } // 全部の範囲を連結してから判定する rep(a, 1, n){ connect(dp[a]); int Lidx = 0; for(auto range: dp[a]){ int l = range.first; int r = range.second; rep(i, Lidx, dp[a-1].size()) { pair prev_range = dp[a-1][i]; if(prev_range.second < l){ Lidx = i; continue; } if(r < prev_range.first) { break; } int nl = max(l, prev_range.first); int nr = min(r, prev_range.second); if(nl <= nr) { dp[a].push_back({nl, nr}); } } } } int q;cin>>q; REP(_,q){ int x;cin>>x; // (l, r]の区間はSxに含まれない int l = -1, r = n; while(l+1 < r){ int mid = (l+r) >> 1; bool inc = false; for(auto range:dp[mid]) { if(range.first <= x && x <= range.second) { inc = true; l = mid; break; } } if(!inc) r = mid; } cout << r << "\n"; } }