#include #include using namespace std; namespace my{ #define eb emplace_back #define LL(...) ll __VA_ARGS__;lin(__VA_ARGS__) #define VL(n,...) vec__VA_ARGS__;setsize({n},__VA_ARGS__);lin(__VA_ARGS__) #define VV(n,...) vec__VA_ARGS__;setsize({n},__VA_ARGS__);vin(__VA_ARGS__) #define FO(n) for(ll ij=n;ij-->0;) #define FOR(i,...) for(auto[i,i##stop,i##step]=range(0,__VA_ARGS__);isync_with_stdio(0);cout<r{0,0,1};ll I=0;((r[I++]=a),...);if(!s&&I==1)swap(r[0],r[1]);r[0]-=s;if(s)r[2]*=-1;return r;} constexpr char newline=10; constexpr char space=32; bool amax(auto&a,const auto&b){return astruct pair{ A a;B b; pair()=default; pair(A a,B b):a(a),b(b){} pair(const std::pair&p):a(p.first),b(p.second){} auto operator<=>(const pair&)const=default; pair operator+(const pair&p)const{return{a+p.a,b+p.b};} friend istream&operator>>(istream&i,pair&p){return i>>p.a>>p.b;} friend ostream&operator<<(ostream&o,const pair&p){return o<>auto&sort(auto&a,F f={}){ranges::sort(a,f);return a;} auto&unique(auto&a){sort(a).erase(ranges::unique(a).begin(),a.end());return a;} templateostream&operator<<(ostream&o,const std::pair&p){return o<ostream&operator<<(ostream&o,const multiset&s){fe(s,e)o<struct multiset:std::multiset{ multiset(const initializer_list&a={}){fe(a,e)this->emplace(e);} multiset(const vector&a){fe(a,e)this->emplace(e);} ll size()const{return std::multiset::size();} T back()const{assert(size());return*this->rbegin();} }; templatestruct set:multiset{ using multiset::multiset; }; templateauto pack_kth(const auto&...a){return get(make_tuple(a...));} templateauto pack_slice_impl(index_sequence, const auto&...a){return array{get(forward_as_tuple(a...))...};} templateauto pack_slice(const auto&...a){return pack_slice_impl(make_index_sequence{},a...);} templateconcept vectorial=is_base_of_v,V>; templatestruct vec_attr{using core_type=T;static constexpr int rank=0;}; templatestruct vec_attr{using core_type=typename vec_attr::core_type;static constexpr int rank=vec_attr::rank+1;}; templateusing core_t=vec_attr::core_type; templateistream&operator>>(istream&i,vector&v){fe(v,e)i>>e;return i;} templateostream&operator<<(ostream&o,const vector&v){fe(v,e)o<?newline:space);return o;} templatestruct vec:vector{ using vector::vector; vec(const vector&v){vector::operator=(v);} templaterequires(sizeof...(A)>=3)vec(A...a){const ll n=sizeof...(a)-1;auto t=pack_slice(a...);ll s[n];fo(i,n)s[i]=t[i];*this=make_vec(s,pack_kth(a...));} templatestatic auto make_vec(const ll(&s)[n],T x){if constexpr(i==n-1)return vec(s[i],x);else{auto X=make_vec(s,x);return vec(s[i],X);}} vec&operator^=(const vec&u){this->insert(this->end(),u.begin(),u.end());return*this;} vec operator^(const vec&u)const{return vec{*this}^=u;} vec&operator+=(const vec&u){vec&v=*this;fo(i,v.size())v[i]+=u[i];return v;} vec&operator-=(const vec&u){vec&v=*this;fo(i,v.size())v[i]-=u[i];return v;} vec operator+(const vec&u)const{return vec{*this}+=u;} vec operator-(const vec&u)const{return vec{*this}-=u;} vec&operator++(){fe(*this,e)++e;return*this;} vec&operator--(){fe(*this,e)--e;return*this;} vec operator-()const{vec v=*this;fe(v,e)e=-e;return v;} ll size()const{return vector::size();} auto lower_bound(const V&x)const{return std::lower_bound(this->begin(),this->end(),x);} ll arg_lower_bound(const V&x)const{return lower_bound(x)-this->begin();} template>auto sort(F f={})const{vec v=*this;ranges::sort(v,f);return v;} }; templatestruct tensor_helper{using type=vec::type>;}; templatestruct tensor_helper<0,T>{using type=T;}; templateusing tensor=typename tensor_helper::type; templaterequires(sizeof...(A)>=2)vec(A...a)->vec(declval>()))>>>; vec(ll)->vec; templatevoid setsize(const ll(&l)[n],A&...a){((a=vec::make_vec(l,core_t{})),...);} void lin(auto&...a){(cin>>...>>a);} void vin(auto&...a){fo(i,(a.size()&...))(cin>>...>>a[i]);} templatevoid pp(const auto&...a){ll n=sizeof...(a);((cout<0,c)),...);cout<auto iota(auto...a){arrayv{};ll I=0;((v[I++]=a),...);if(I==1)swap(v[0],v[1]);vecr;fo(i,v[0],v[1])r.eb(i);return r;} auto zip(auto&...a){auto v=(a^...);unique(v);([&](auto&u){fe(u,e)e=v.arg_lower_bound(e);}(a),...);return v;} ll mex(const set&s){ll r=0;while(s.count(r))++r;return r;} ll mex(const vec&v){return mex(set(v));} void sort(auto&...a){vec>v;(v.eb(a),...);sort(v);ll I=0;((a=v[I++]),...);} templateauto complement_interval_enumerate(ll n,vec>p){ vec>res; unique(p); ll cu=0; fo(i,p.size()){ if(custruct range_mex_offline{ vecdata; range_mex_offline(ll n,const vec&l,const vec&r,const vec&a){ ll m=l.size(); data.resize(n); vec>>g(m+1); fo(i,m)if(a[i]s(iota(n)); fo(x,m+1){ ll cu=0; fe(complement_interval_enumerate(n,g[x]),l,r){ auto p=s.lower_bound(l); auto q=s.lower_bound(r); for(auto it=p;it!=q;it++)data[*it]=x; s.erase(p,q); } } } ll mex(ll i)const{return data[i];} }; single_testcase void solve(){ LL(M); VV(M,l,r,a);--l; LL(Q); VL(Q,x);--x; ll N=zip(l,r,x).size(); range_mex_offlinermo(N,l,r,a); fo(q,Q)pp(rmo.mex(x[q])); }}