#ifdef LOCAL #include #else #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2") #include #define debug(...) (static_cast(0)) #define postprocess() (static_cast(0)) #endif // #include "atcoder/dsu.hpp" // #include "atcoder/modint.hpp" // using mint = atcoder::modint998244353; // using mint = atcoder::modint1000000007; using namespace std; using ll = long long; using ld = long double; void solve([[maybe_unused]] int test) { // 1: l_i, a_i // 2: x_i, i // 3: r_i, a_i vector> queries; int N; cin >> N; for (int i = 0; i < N; i++) { int l, r, a; cin >> l >> r >> a; if (a <= N) { queries.push_back({l, 1, a}); queries.push_back({r, 3, a}); } } int Q; cin >> Q; for (int i = 0; i < Q; i++) { int x; cin >> x; queries.push_back({x, 2, i}); } sort(queries.begin(), queries.end()); optional ans[Q]; int num[N + 1]; set not_included; for (int i = 0; i <= N; i++) { num[i] = 0; not_included.insert(i); } for (auto&& query : queries) { int type = get<1>(query); if (type == 1) { int l, a; tie(l, ignore, a) = query; num[a] += 1; not_included.erase(a); } if (type == 3) { int r, a; tie(r, ignore, a) = query; num[a] -= 1; if (num[a] == 0) not_included.insert(a); } if (type == 2) { int x, i; tie(x, ignore, i) = query; ans[i] = *not_included.begin(); } } for (int i = 0; i < Q; i++) { cout << ans[i].value_or(-1) << '\n'; } } int main() { ios::sync_with_stdio(false), cin.tie(nullptr); int t = 1; // cin >> t; for (int _t = 1; _t <= t; _t++) solve(_t); postprocess(); }