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"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))

// Monoid: オブジェクト
// OperatorMonoid: オブジェクトに作用する変数
// f,g,hがどこで使用されているかを見るとやりやすい
template<typename Monoid, typename OperatorMonoid = Monoid>
class LazySegmentTree {
private:
	using F = function<Monoid(Monoid, Monoid)>;
	using G = function<Monoid(Monoid, OperatorMonoid, int)>;
	using H = function<OperatorMonoid(OperatorMonoid, OperatorMonoid)>;

	int sz; // 対応する配列の幅
	vector<Monoid> data;
	vector<OperatorMonoid> lazy;
	const F f; // 2区間マージ演算(data-dataマージ)
	const G g; // 要素,作用素マージ演算(lazy->data伝搬時の、(data,lazy,len)の計算)
	const H h; // 作用素マージ演算　(query->lazy伝搬時の、(lazy,query_value)の計算)
	const Monoid M1;          // モノイド単位元　(data単位元)
	const OperatorMonoid OM0; // 作用素単位元 (lazy単位元)

	void propagate(int idx, int len) {
		// 幅lenのlazy[idx]が存在するとき、値を下に流す
		if (lazy[idx] != OM0) {
			if (idx < sz) {
				lazy[(idx << 1) | 0] = h(lazy[(idx << 1) | 0], lazy[idx]);
				lazy[(idx << 1) | 1] = h(lazy[(idx << 1) | 1], lazy[idx]);
			}
			data[idx] = g(data[idx], lazy[idx], len);
			lazy[idx] = OM0;
		}
	}
	Monoid update_impl(int a, int b, const OperatorMonoid& val, int idx, int l, int r) {
		propagate(idx, r - l);
		if (r <= a || b <= l)return data[idx];
		else if (a <= l && r <= b) {
			lazy[idx] = h(lazy[idx], val);
			propagate(idx, r - l);
			return data[idx];
		}
		else return data[idx] = f(
			update_impl(a, b, val, (idx << 1) | 0, l, (l + r) >> 1),
			update_impl(a, b, val, (idx << 1) | 1, (l + r) >> 1, r)
		);
	}
	Monoid query_impl(int a, int b, int idx, int l, int r) {
		propagate(idx, r - l);
		if (r <= a || b <= l)return M1;
		else if (a <= l && r <= b)return data[idx];
		else return f(
			query_impl(a, b, (idx << 1) | 0, l, (l + r) >> 1),
			query_impl(a, b, (idx << 1) | 1, (l + r) >> 1, r)
		);
	}

public:
	// init忘れに注意
	LazySegmentTree(int n, const F f, const G g, const H h,
		const Monoid& M1, const OperatorMonoid OM0)
		:f(f), g(g), h(h), M1(M1), OM0(OM0) {
		sz = 1;
		while (sz < n)sz <<= 1;
		data.assign(2 * sz, M1);
		lazy.assign(2 * sz, OM0);
	}
	void build(const vector<Monoid>& vals) {
		rep(idx, vals.size())data[idx + sz] = vals[idx];
		for (int idx = sz - 1; idx > 0; idx--) {
			data[idx] = f(data[(idx << 1) | 0], data[(idx << 1) | 1]);
		}
	}
	Monoid update(int a, int b, const OperatorMonoid& val) {
		return update_impl(a, b, val, 1, 0, sz);
	}
	Monoid query(int a, int b) {
		return query_impl(a, b, 1, 0, sz);
	}
	Monoid operator[](const int& idx) {
		return query(idx, idx + 1);
	}
};

int main()
{
	int N, Q;
	cin >> N >> Q;

	constexpr int MONOID_E = 1000000001;
	vector<vector<int>> stx(N, vector<int>(3));
	vector<int> D(Q);
	set<int> st;
	map<int, int> mp;
	rep(i, N)rep(j, 3)cin >> stx[i][j];
	rep(q, Q) {
		cin >> D[q];
		st.insert(D[q]);
		mp[D[q]] = q;
	}
	auto f = [](int a, int b) {return min(a, b); };
	auto g = [](int a, int b, int sz) {return min(a, b); };
	LazySegmentTree<int> lst(Q, f, g, f, MONOID_E, MONOID_E);

	for (auto query : stx) {
		int s = query[0], t = query[1], x = query[2];
		s -= x, t -= x;

		auto itrs = st.lower_bound(s);
		if (itrs == st.end())continue;
		s = mp[*itrs];

		auto itrt = st.lower_bound(t);
		t = itrt == st.end() ? N : mp[*itrt];

		if (s > t)continue;
		lst.update(s, t, x);
	}
	rep(i, Q) {
		int ans = lst.query(i, i + 1);
		cout << (ans == MONOID_E ? -1 : ans) << endl;
	}
	return 0;
}