Problem:
Score : 500 points

Problem Statement

There is an infinitely long street that runs west to east, which we consider as a number line.

There are N roadworks scheduled on this street.
The i-th roadwork blocks the point at coordinate X_i from time S_i - 0.5 to time T_i - 0.5.

Q people are standing at coordinate 0. The i-th person will start the coordinate 0 at time D_i, continue to walk with speed 1 in the positive direction and stop walking when reaching a blocked point.

Find the distance each of the Q people will walk.

Constraints

All values in input are integers.

1 \leq N, Q \leq 2 \times 10^5

0 \leq S_i < T_i \leq 10^9

1 \leq X_i \leq 10^9

0 \leq D_1 < D_2 < ... < D_Q \leq 10^9

If i \neq j and X_i = X_j, the intervals [S_i, T_i) and [S_j, T_j) do not overlap.

Input

Input is given from Standard Input in the following format:

N Q
S_1 T_1 X_1
:
S_N T_N X_N
D_1
:
D_Q

Output

Print Q lines. The i-th line should contain the distance the i-th person will walk or -1 if that person walks forever.

Sample Input 1

4 6
1 3 2
7 13 10
18 20 13
3 4 2
0
1
2
3
5
8

Sample Output 1

2
2
10
-1
13
-1

The first person starts coordinate 0 at time 0 and stops walking at coordinate 2 when reaching a point blocked by the first roadwork at time 2.

The second person starts coordinate 0 at time 1 and reaches coordinate 2 at time 3. The first roadwork has ended, but the fourth roadwork has begun, so this person also stops walking at coordinate 2.

The fourth and sixth persons encounter no roadworks while walking, so they walk forever. The output for these cases is -1.

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>

#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)

#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define op(i) cout << (i) << endl;
#define F first
#define S second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const ll mod = 1e9 + 7;
const int infi = 2147483647;
const ll infl = 1e17;

struct SegmentTree{
    private:
        using F = function<ll(ll, ll)>;
        int N;
        vector<ll> node;
        F f;
        ll e;
    public:
        SegmentTree(){}
        SegmentTree(F f, ll e):f(f),e(e){}
        void __init__(int sz){
            N = 1;
            while (N<sz)
                N <<= 1;
            node.assign(2 * N - 1, e);
        }
        void build(vector<ll>& v){
            int sz = int(v.size());
            __init__(sz);
            rep(i,sz){
                node[i + N - 1] = v[i];
            }
            for (int i = N - 2; i >= 0;i--){
                node[i] = f(node[i * 2 + 1], node[i * 2 + 2]);
            }
        }
        void update(int k, ll x)
        {
            k += N - 1;
            node[k] = x;
            while (k > 0)
            {
                k = (k - 1) / 2;
                node[k] = f(node[2 * k + 1], node[2 * k + 2]);
            }
        }
        void renew(int b,int e,ll x){renew(b, e, 0, 0, N, x);
            return;
        }
        void renew(int b,int e,int k,int l,int r,ll x){
            if(e<l || r<b || e<=0 || b>=N)
                return;
            if (k>0){
                node[k] = f(node[k], node[(k - 1) / 2]);
            }
            if (b<=l && r<=e){
                node[k] = f(node[k], x);
                return;
            }
            else if (k<N-1){
                renew(b, e, 2 * k + 1, l, (l + r) / 2, x);
                renew(b, e, 2 * k + 2, (l + r) / 2, r, x);
                return;
            }
            return;
            }
        
        ll get(int i){
            int k = i;
            ll res = node[k + N - 1];
            while (k>0){
                k = (k - 1) / 2;
                res = f(res, node[k]);
            }
            return res;
        }
        ll query(int a, int b) { return query(a, b, 0, 0, N); }
        ll query(int a,int b,int k,int l,int r){
            if(b<=l || r<=a)
                return e;
            if (a<=l && r<=b)
                return node[k];
            ll vl, vr;
            vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
            vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
            return f(vl, vr);
        }
        void show(){
            rep(i, N) cout << node[i] << " ";
            cout << endl;
            return;
        }
};

auto funcmin = [=](ll a, ll b) { return min(a, b); };
SegmentTree seg(funcmin, infl);


int main()
{
    int N, Q;
    cin >> N >> Q;
    vvll stop(N, vll(3, 0));
    rep(i,N){
        ll s, t, x;
        cin >> s >> t >> x;
        stop[i][0] = s - x;
        stop[i][1] = t - x;
        stop[i][2] = x;
    }
    vll D(Q);
    rep(i, Q) cin >> D[i];
    seg.__init__(Q);
    rep(i,N){
        int b = lower_bound(all(D), stop[i][0]) - D.begin();
        int e = lower_bound(all(D), stop[i][1]) - D.begin();
        seg.renew(b, e,stop[i][2]);
    }
    rep(i, Q){
        ll ans = seg.get(i);
        if (ans==infl)
            cout << -1 << endl;
        else
            cout << ans << endl;
    }
}