#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(){ std::cin.tie(0)->sync_with_stdio(0); int n;std::cin>>n; vector>> op(n); REP(i,n){ int l, r,a; std::cin>>l>>r>>a; op[i] = {a, {l, r}}; } sort(All(op)); // 数iを含む区間[l,r]の範囲 vector>> rgs(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{ rgs[a].push_back(range); } } vector>> dp(n); // 全部の範囲を連結してから判定する dp[0] = rgs[0]; connect(dp[0]); rep(a, 1, n){ connect(rgs[a]); int Lidx = 0; for(const auto &range: rgs[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+1; 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;std::cin>>q; REP(_,q){ int x;std::cin>>x; // (l, r]の区間はSxに含まれない int l = -1, r = n; while(l+1 < r){ int mid = (l+r) >> 1; bool inc = false; int lidx = -1, ridx = dp[mid].size() - 1; while(lidx + 1 < ridx) { int midx = (lidx + ridx) >> 1; pair range = dp[mid][midx]; if(x < range.first) { lidx = midx; } else{ ridx = midx; } } pair range = dp[mid][ridx]; if(range.first <= x && x <= range.second) { inc = true; l = mid; break; } else r = mid; } cout << r << "\n"; } }