Language: C++

#include<bits/stdc++.h>

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;
#define rep(i,s,e) for(int i = (int)(s); i < (int)(e); ++i)
#define per(i,s,e) for(int i = (int)(s)-1; i >= (int)(e); --i)

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n, q; cin >> n >> q;
  vector<tuple<int,int,int>> v(n);
  for(auto&e:v){
    int a,b,c; cin >> a >> b >> c;
    e = tie(c,a,b);
  }
  set<P<int,int>> d;
  rep(i,0,q){int x; cin >> x;d.insert({x,i});}
  sort(v.begin(),v.end());
  vector<int> ans(q,-1);
  auto cmp = [](P<int,int>&a,int b){return a.first < b;};
  for(auto&t:v){
    auto b = lower_bound(d.begin(), d.end(), get<1>(t)-get<0>(t),cmp);
    auto e = lower_bound(d.begin(), d.end(), get<2>(t)-get<0>(t),cmp);
    for(auto it = b; it != e; ++it){
      ans[it->second] = get<0>(t);
    }
    d.erase(b,e);
  }
  for(auto&e:ans){
    cout << e << endl;
  }
  return 0;
}


Compiler output:
In file included from /usr/include/c++/14/bits/stl_algobase.h:71,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Iter_comp_val<_Compare>::operator()(_Iterator, _Value&) [with _Iterator = std::_Rb_tree_const_iterator<std::pair<int, int> >; _Value = const int; _Compare = main()::<lambda(P<int, int>&, int)>]':
/usr/include/c++/14/bits/stl_algobase.h:1504:14:   required from '_ForwardIterator std::__lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&, _Compare) [with _ForwardIterator = _Rb_tree_const_iterator<pair<int, int> >; _Tp = int; _Compare = __gnu_cxx::__ops::_Iter_comp_val<main()::<lambda(P<int, int>&, int)> >]'
 1504 |           if (__comp(__middle, __val))
      |               ~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1973:32:   required from '_FIter std::lower_bound(_FIter, _FIter, const _Tp&, _Compare) [with _FIter = _Rb_tree_const_iterator<pair<int, int> >; _Tp = int; _Compare = main()::<lambda(P<int, int>&, int)>]'
 1973 |       return std::__lower_bound(__first, __last, __val,
      |              ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
 1974 |                                 __gnu_cxx::__ops::__iter_comp_val(__comp));
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:51:25:   required from here
   51 |     auto b = lower_bound(d.begin(), d.end(), get<1>(t)-get<0>(t),cmp);
      |              ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h:196:30: error: no match for call to '(main()::<lambda(P<int, int>&, int)>) (const std::pair<int, int>&, const int&)'
  196 |         { return bool(_M_comp(*__it, __val)); }
      |                       ~~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h:196:30: note: candidate: 'bool (*)(P<int, int>&, int)' {aka 'bool (*)(std::pair<int, int>&, int)'} (conversion)
/usr/include/c++/14/bits/predefined_ops.h:196:30: note:   conversion of argument 2 would be ill-formed:
/usr/include/c++/14/bits/predefined_ops.h:196:30: error: binding reference of type 'P<int, int>&' {aka 'std::pair<int, int>&'} to 'const std::pair<int, int>' discards qualifiers
a.cc:49:14: note: candidate: 'main()::<lambda(P<int, int>&, int)>' (near match)
   49 |   auto cmp = [](P<int,int>&a,int b){return a.first < b;};
      |              ^
a.cc:49:14: note:   conversion of argument 1 would be ill-formed:
a.cc:49:14: error: binding reference of type 'P<int, int>&' {aka 'std::pair<int, int>&'} to 'const std::pair<int, int>' discards qualifiers