Language: C++

/*
 * atcoder/abc128/e.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

/*
 *    0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * 0  2 2 10    - -
 * 1    a b c     e
 * 2    --- - c     e
 * 3            c     e
 * 4              c     e
 * 5                c     e
 * 6                  c      e
 * 7                    c       e
 * 8                      c        e
 * 9                         c        e
 * 10               -------------        e
 * 11                                       e
 * 12                                          e
 * 13                                             ----
 *
 * 最終的にぶつかるかどうかはすべて0地点の時間をマッピングすればO(1)で分かる.
 * 後は、衝突までの時間もO(1)で取る方法を考えれば良い.
 * 0地点にマッピングする際にその地点にマッピングされる最小のXを保持する. それがO(1)で取れる.
 *
 */
template<class Monoid, class Action> struct SegTree {
    using FuncMonoid = function< Monoid(Monoid, Monoid) >;
    using FuncAction = function< void(Monoid&, Action) >;
    using FuncLazy = function< void(Action&, Action) >;
    FuncMonoid FM;
    FuncAction FA;
    FuncLazy FL;
    Monoid UNITY_MONOID;
    Action UNITY_LAZY;
    int SIZE, HEIGHT;
    vector<Monoid> dat;
    vector<Action> lazy;
    
    SegTree() { }
    SegTree(int n, const FuncMonoid fm, const FuncAction fa, const FuncLazy fl,
            const Monoid &unity_monoid, const Action &unity_lazy)
    : FM(fm), FA(fa), FL(fl), UNITY_MONOID(unity_monoid), UNITY_LAZY(unity_lazy) {
        SIZE = 1; HEIGHT = 0;
        while (SIZE < n) SIZE <<= 1, ++HEIGHT;
        dat.assign(SIZE * 2, UNITY_MONOID);
        lazy.assign(SIZE * 2, UNITY_LAZY);
    }
    void init(int n, const FuncMonoid fm, const FuncAction fa, const FuncLazy fl,
              const Monoid &unity_monoid, const Action &unity_lazy) {
        FM = fm; FA = fa; FL = fl;
        UNITY_MONOID = unity_monoid; UNITY_LAZY = unity_lazy;
        SIZE = 1; HEIGHT = 0;
        while (SIZE < n) SIZE <<= 1, ++HEIGHT;
        dat.assign(SIZE * 2, UNITY_MONOID);
        lazy.assign(SIZE * 2, UNITY_LAZY);
    }
    
    /* set, a is 0-indexed */
    void set(int a, const Monoid &v) { dat[a + SIZE] = v; }
    void build() {
        for (int k = SIZE - 1; k > 0; --k)
            dat[k] = FM(dat[k*2], dat[k*2+1]);
    }
    
    /* update [a, b) */
    inline void evaluate(int k) {
        if (lazy[k] == UNITY_LAZY) return;
        if (k < SIZE) FL(lazy[k*2], lazy[k]), FL(lazy[k*2+1], lazy[k]);
        FA(dat[k], lazy[k]);
        lazy[k] = UNITY_LAZY;
    }
    inline void update(int a, int b, const Action &v, int k, int l, int r) {
        evaluate(k);
        if (a <= l && r <= b)  FL(lazy[k], v), evaluate(k);
        else if (a < r && l < b) {
            update(a, b, v, k*2, l, (l+r)>>1), update(a, b, v, k*2+1, (l+r)>>1, r);
            dat[k] = FM(dat[k*2], dat[k*2+1]);
        }
    }
    inline void update(int a, int b, const Action &v) { update(a, b, v, 1, 0, SIZE); }
    
    /* get [a, b) */
    inline Monoid get(int a, int b, int k, int l, int r) {
        evaluate(k);
        if (a <= l && r <= b)
            return dat[k];
        else if (a < r && l < b)
            return FM(get(a, b, k*2, l, (l+r)>>1), get(a, b, k*2+1, (l+r)>>1, r));
        else
            return UNITY_MONOID;
    }
    inline Monoid get(int a, int b) { return get(a, b, 1, 0, SIZE); }
    inline Monoid operator [] (int a) { return get(a, a+1); }
    
    /* debug */
    void print() {
        for (int i = 0; i < SIZE; ++i) { cout << (*this)[i]; if (i != SIZE) cout << ","; }
        cout << endl;
    }
};
ll N, Q;
vector<ll> S, T, X, D, C;
void solve() {
  cin >> N >> Q;
  S.resize(N);
  T.resize(N);
  X.resize(N);
  D.resize(Q);
  C.push_back(-(1LL<<60));
  C.push_back(1LL<<60);
  loop(n,0,N) {
    cin >> S[n] >> T[n] >> X[n];
    C.push_back(S[n]-X[n]);
    C.push_back(T[n]-X[n]);
  }
  loop(q,0,Q) {
    cin >> D[q];
    C.push_back(D[q]);
  }
  sort(C.begin(), C.end());
  C.erase(unique(C.begin(), C.end()), C.end());

  ll INF = numeric_limits<ll>::max();
  auto fm = [](ll a, ll b) { return min(a, b); };
  auto fa = [](ll &a, ll d) { chmin(a, d); };
  auto fl = [](ll &d, ll e) { chmin(d, e); };
  ll M = C.size();
  SegTree<ll, ll> rmq(M + 10, fm, fa, fl, INF, INF);

  ll x, y;
  loop(n,0,N) {
    x = lower_bound(C.begin(), C.end(), S[n]-X[n]) - C.begin();
    y = lower_bound(C.begin(), C.end(), T[n]-X[n]) - C.begin();
    rmq.update(x, y, X[n]);
  }

  loop(q,0,Q) {
    x = lower_bound(C.begin(), C.end(), D[q]) - C.begin();
    ll val = rmq.get(x, x+1);
    if (val == INF) cout << -1 << endl;
    else cout << val << endl;
  }
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


Compiler output:
a.cc:45:24: error: 'function' does not name a type; did you mean 'Action'?
   45 |     using FuncMonoid = function< Monoid(Monoid, Monoid) >;
      |                        ^~~~~~~~
      |                        Action
a.cc:46:24: error: 'function' does not name a type; did you mean 'Action'?
   46 |     using FuncAction = function< void(Monoid&, Action) >;
      |                        ^~~~~~~~
      |                        Action
a.cc:47:22: error: 'function' does not name a type; did you mean 'Action'?
   47 |     using FuncLazy = function< void(Action&, Action) >;
      |                      ^~~~~~~~
      |                      Action
a.cc:48:5: error: 'FuncMonoid' does not name a type; did you mean 'Monoid'?
   48 |     FuncMonoid FM;
      |     ^~~~~~~~~~
      |     Monoid
a.cc:49:5: error: 'FuncAction' does not name a type; did you mean 'Action'?
   49 |     FuncAction FA;
      |     ^~~~~~~~~~
      |     Action
a.cc:50:5: error: 'FuncLazy' does not name a type
   50 |     FuncLazy FL;
      |     ^~~~~~~~
a.cc:58:26: error: 'FuncMonoid' does not name a type; did you mean 'Monoid'?
   58 |     SegTree(int n, const FuncMonoid fm, const FuncAction fa, const FuncLazy fl,
      |                          ^~~~~~~~~~
      |                          Monoid
a.cc:58:47: error: 'FuncAction' does not name a type; did you mean 'Action'?
   58 |     SegTree(int n, const FuncMonoid fm, const FuncAction fa, const FuncLazy fl,
      |                                               ^~~~~~~~~~
      |                                               Action
a.cc:58:68: error: 'FuncLazy' does not name a type
   58 |     SegTree(int n, const FuncMonoid fm, const FuncAction fa, const FuncLazy fl,
      |                                                                    ^~~~~~~~
a.cc:66:28: error: 'FuncMonoid' does not name a type; did you mean 'Monoid'?
   66 |     void init(int n, const FuncMonoid fm, const FuncAction fa, const FuncLazy fl,
      |                            ^~~~~~~~~~
      |                            Monoid
a.cc:66:49: error: 'FuncAction' does not name a type; did you mean 'Action'?
   66 |     void init(int n, const FuncMonoid fm, const FuncAction fa, const FuncLazy fl,
      |                                                 ^~~~~~~~~~
      |                                                 Action
a.cc:66:70: error: 'FuncLazy' does not name a type
   66 |     void init(int n, const FuncMonoid fm, const FuncAction fa, const FuncLazy fl,
      |                                                                      ^~~~~~~~
a.cc: In constructor 'SegTree<Monoid, Action>::SegTree(int, int, int, int, const Monoid&, const Action&)':
a.cc:60:7: error: class 'SegTree<Monoid, Action>' does not have any field named 'FM'
   60 |     : FM(fm), FA(fa), FL(fl), UNITY_MONOID(unity_monoid), UNITY_LAZY(unity_lazy) {
      |       ^~
a.cc:60:15: error: class 'SegTree<Monoid, Action>' does not have any field named 'FA'
   60 |     : FM(fm), FA(fa), FL(fl), UNITY_MONOID(unity_monoid), UNITY_LAZY(unity_lazy) {
      |               ^~
a.cc:60:23: error: class 'SegTree<Monoid, Action>' does not have any field named 'FL'
   60 |     : FM(fm), FA(fa), FL(fl), UNITY_MONOID(unity_monoid), UNITY_LAZY(unity_lazy) {
      |                       ^~
a.cc: In member function 'void SegTree<Monoid, Action>::init(int, int, int, int, const Monoid&, const Action&)':
a.cc:68:9: error: 'FM' was not declared in this scope; did you mean 'fm'?
   68 |         FM = fm; FA = fa; FL = fl;
      |         ^~
      |         fm
a.cc:68:18: error: 'FA' was not declared in this scope; did you mean 'fa'?
   68 |         FM = fm; FA = fa; FL = fl;
      |                  ^~
      |                  fa
a.cc:68:27: error: 'FL' was not declared in this scope; did you mean 'fl'?
   68 |         FM = fm; FA = fa; FL = fl;
      |                           ^~
      |                           fl
a.cc: In function 'void solve()':
a.cc:146:31: error: invalid user-defined conversion from 'solve()::<lambda(long long int, long long int)>' to 'int' [-fpermissive]
  146 |   SegTree<ll, ll> rmq(M + 10, fm, fa, fl, INF, INF);
      |                               ^~
a.cc:142:13: note: candidate is: 'constexpr solve()::<lambda(long long int, long long int)>::operator long long int (*)(long long int, long long int)() const' (near match)
  142 |   auto fm = [](ll a, ll b) { return min(a, b); };
      |             ^
a.cc:142:13: note:   no known conversion from 'long long int (*)(long long int, long long int)' to 'int'
a.cc:58:37: note:   initializing argument 2 of 'SegTree<Monoid, Action>::SegTree(int, int, int, int, const Monoid&, const Action&) [with Monoid = long long int; Action = long long int]'
   58 |     SegTree(int n, const FuncMonoid fm, const FuncAction fa, const FuncLazy fl,
      |                    ~~~~~~~~~~~~~~~~~^~
a.cc:146:35: error: invalid user-defined conversion from 'solve()::<lambda(long long int&, long long int)>' to 'int' [-fpermissive]
  146 |   SegTree<ll, ll> rmq(M + 10, fm, fa, fl, INF, INF);
      |                                   ^~
a.cc:143:13: note: candidate is: 'constexpr solve()::<lambda(long long int&, long long int)>::operator void (*)(long long int&, long long int)() const' (near match)
  143 |   auto fa = [](ll &a, ll d) { chmin(a, d); };
      |             ^
a.cc:143:13: note:   no known conversion from 'void (*)(long long int&, long long int)' to 'int'
a.cc:58:58: note:   initializing argument 3 of 'SegTree<Monoid, Action>::SegTree(int, int, int, int, const Monoid&, const Action&) [with Monoid = long long int; Action = long long int]'
   58 |     SegTree(int n, const FuncMonoid fm, const FuncAction fa, const FuncLazy fl,
      |                                         ~~~~~~~~~~~~~~~~~^~
a.cc:146:39: error: invalid user-defined conversion from 'solve()::<lambda(long long int&, long long int)>' to 'int' [-fpermissive]
  146 |   SegTree<ll, ll> rmq(M + 10, fm, fa, fl, INF, INF);
      |                                       ^~
a.cc:144:13: note: candidate is: 'constexpr solve()::<lambda(long long int&, long long int)>::operator void (*)(long long int&, long long int)() const' (near match)
  144 |   auto fl = [](ll &d, ll e) { chmin(d, e); };
      |             ^
a.cc:144:13: note:   no known conversion from 'void (*)(long long int&, long long int)' to 'int'
a.cc:58:77: note:   initializing argument 4 of 'SegTree<Monoid, Action>::SegTree(int, int, int, int, const Monoid&, const Action&) [with Monoid = long long int; Action = long long int]'
   58 |     SegTree(int n, const FuncMonoid fm, const FuncAction fa, const FuncLazy fl,
      |                                                              ~~~~~~~~~~~~~~~^~
a.cc: In instantiation of 'void SegTree<Monoid, Action>::update(int, int, const Action&, int, int, int) [with Monoid = long long int; Action = long long int]':
a.cc:98:63:   required from 'void SegTree<Monoid, Action>::update(int, int, const Action&) [with Monoid = long long int; Action = long long int]'
   98 |     inline void update(int a, int b, const Action &v) { update(a, b, v, 1, 0, SIZE); }
      |                                                         ~~~~~~^~~~~~~~~~~~~~~~~~~~~
a.cc:152:15:   required from here
  152 |     rmq.update(x, y, X[n]);
      |     ~~~~~~~~~~^~~~~~~~~~~~
a.cc:92:34: error: 'FL' was not declared in this scope
   92 |         if (a <= l && r <= b)  FL(lazy[k], v), evaluate(k);
      |                                ~~^~~~~~~~~~~~
a.cc:95:24: error: 'FM' was not declared in this scope
   95 |             dat[k] = FM(dat[k*2], dat[k*2+1]);
      |                      ~~^~~~~~~~~~~~~~~~~~~~~~
a.cc: In instantiation of 'Monoid SegTree<Monoid, Action>::get(int, int, int, int, int) [with Monoid = long long int; Action = long long int]':
a.cc:110:49:   required from 'Monoid SegTree<Monoid, Action>::get(int, int) [with Monoid = long long int; Action = long long int]'
  110 |     inline Monoid get(int a, int b) { return get(a, b, 1, 0, SIZE); }
      |                                              ~~~^~~~~~~~~~~~~~~~~~
a.cc:157:21:   required from here
  157 |     ll val = rmq.get(x, x+1);
      |              ~~~~~~~^~~~~~~~
a.cc:106:22: error: 'FM' was not declared in this scope
  106 |             return FM(get(a, b, k*2, l, (l+r)>>1), get(a, b, k*2+1, (l+r)>>1, r));
      |                    ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc: In instantiation of 'void SegTree<Monoid, Action>::evaluate(int) [with Monoid = long long int; Action = long long int]':
a.cc:91:9:   required from 'void SegTree<Monoid, Action>::update(int, int, const Action&, int, int, int) [with Monoid = long long int; Action = long long int]'
   91 |         evaluate(k);
      |         ^~~~~~~~
a.cc:98:63:   required from 'void SegTree<Monoid, Action>::update(int, int, const Action&) [with Monoid = long long int; Action = long long int]'
   98 |     inline void update(int a, int b, const Action &v) { update(a, b, v, 1, 0, SIZE); }
      |                                                         ~~~~~~^~~~~~~~~~~~~~~~~~~~~
a.cc:152:15:   required from here
  152 |     rmq.update(x, y, X[n]);
      |     ~~~~~~~~~~^~~~~~~~~~~~
a.cc:86:25: error: 'FL' was not declared in this scope
   86 |         if (k < SIZE) FL(lazy[k*2], lazy[k]), FL(lazy[k*2+1], lazy[k]);
      |                       ~~^~~~~~~~~~~~~~~~~~~~
a.cc:86:49: error: 'FL' was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation
   86 |         if (k < SIZE) FL(lazy[k*2], lazy[k]), FL(lazy[k*2+1], lazy[k]);
      |                                               ~~^~~~~~~~~~~~~~~~~~~~~~
a.cc:86:25: note: 'FL' declared here, later in the translation unit
   86 |         if (k < SIZE) FL(lazy[k*2], lazy[k]), FL(lazy[k*2+1], lazy[k]);
      |                       ~~^~~~~~~~~~~~~~~~~~~~
a.cc:87:11: error: 'FA' was not declared in this scope
   87 |         FA(dat[k], lazy[k]);
      |         ~~^~~~~~~~~~~~~~~~~