Language: C++

#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define debug(v) cout << #v<< ": " << v <<endl;
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL<<60;
ll M = 1000000007;

int main(){
    ll N, q; cin >> N >> q;
    vector<tuple<ll, ll, ll>> cst(0);
    rep(i, 0, N){
        ll a, b, c; cin >> a >> b >> c;
        cst.emplace_back(c, a-c, b-c);
    }
    sort(cst.begin(),cst.end());
    vvll res(0, vll(2));
    set<ll> t;
    t.insert(INF);
    vll lis;
    rep(i, 0, q){
        ll v; cin >> v;
        t.insert(v);
        lis.emplace_back(v);
    }
    for(auto x: cst){
        ll X = get<0>(x), s = get<1>(x), e =  get<2>(x);
        auto r = t.lower_bound(s); auto u = t.upper_bound(e-1);
        //debug(X);
        //debug(s);
        //debug(e);
        iterator f = r;
        rep(i, 0, N){
            if(f == u){
                break;
            }
            ll g = *f;
            vll h = {g, X};
            res.emplace_back(h);
            f = next(f, 1);
        }
        f = r;
        rep(i, 0, N){
            if(f == u){
                break;
            }
            ll g = *f;
            //prt(g); prt(" ");
            t.erase(g);
            f = next(f, 1);
        }
        //prt(endl);
    }
    ll m = 0;
    sort(res.begin(),res.end());
    ll w = sz(res);
    for(auto x: lis){
        if(m < w){
            if(res[m][0] == x){
                prtl(res[m][1]);
                m++;
            }else{
                prtl(-1);
            }
        }else{
            prtl(-1);
        }
    }
}








Compiler output:
a.cc: In function 'int main()':
a.cc:53:22: error: class template argument deduction failed:
   53 |         iterator f = r;
      |                      ^
a.cc:53:22: error: no matching function for call to 'iterator(std::_Rb_tree_const_iterator<long long int>&)'
In file included from /usr/include/c++/14/bits/stl_algobase.h:65,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_iterator_base_types.h:127:34: note: candidate: 'template<class _Category, class _Tp, class _Distance, class _Pointer, class _Reference> iterator()-> std::iterator<_Category, _Tp, _Distance, _Pointer, _Reference>'
  127 |     struct _GLIBCXX17_DEPRECATED iterator
      |                                  ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_types.h:127:34: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/14/bits/stl_iterator_base_types.h:127:34: note: candidate: 'template<class _Category, class _Tp, class _Distance, class _Pointer, class _Reference> iterator(std::iterator<_Category, _Tp, _Distance, _Pointer, _Reference>)-> std::iterator<_Category, _Tp, _Distance, _Pointer, _Reference>'
/usr/include/c++/14/bits/stl_iterator_base_types.h:127:34: note:   template argument deduction/substitution failed:
a.cc:53:22: note:   'std::_Rb_tree_const_iterator<long long int>' is not derived from 'std::iterator<_Category, _Tp, _Distance, _Pointer, _Reference>'
   53 |         iterator f = r;
      |                      ^