#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;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]; rep(a, 1, n){ connect(rgs[a]); int Lidx = 0; for(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; 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; for(auto range:dp[mid]) { if(range.first <= x && x <= range.second) { inc = true; l = mid; break; } } if(!inc) r = mid; } cout << r << "\n"; } }