1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
using PII = pair<int, int>;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using VVV = vector<VV<T>>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back
const ll INF = (1LL<<60);
const int MOD = 1000000007;
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
out<<'('<<a.first<<','<<a.second<<')';
return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
out<<'[';
REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
out<<']';
return out;
}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
/**
* @brief セグメント木
* @details 抽象化した遅延セグメント木\n
* 区間更新区間max d1=d0=INT_MAX f=max(a,b) g=h=(b==INT_MAX?a:b)\n
* 区間加算区間和 d1=d0=0 f=g=h=a+b p=a*b\n
* 区間加算区間min d1=d0=0 f=min(a,b) g=h=a+b\n
* 区間更新区間和 d1=d0=0 f=a+b g=h=(b==0?a:b) p=a*b\n
* 区間xor区間和 d1=d0=0 f=a+b g=(b>=1?b-a:a) h=a^b p=a*b
*/
template <typename T, typename E>
struct lazySegTree {
using F = function<T(T,T)>;
using G = function<T(T,E)>;
using H = function<E(E,E)>;
using P = function<E(E,int)>;
F f; G g; H h; P p; T d1; E d0;
int n;
vector<int> dat, lazy;
lazySegTree(){}
lazySegTree(int n_, F f_, G g_, H h_,
T d1_, E d0_, P p_=[](E a, int b){return a;})
: f(f_), g(g_), h(h_), p(p_), d1(d1_), d0(d0_)
{
n = 1; while(n < n_) n *= 2;
dat.assign(n*2, d1);
lazy.assign(n*2, d0);
}
void build(vector<T> v) {
REP(i, v.size()) dat[i+n-1] = v[i];
for(int i=n-2; i>=0; --i) dat[i] = f(dat[i*2+1], dat[i*2+2]);
}
// 区間の幅がlenの節点kについて遅延評価
inline void eval(int len, int k) {
if(lazy[k] == d0) return;
if(k*2+1 < n*2-1) {
lazy[2*k+1] = h(lazy[k*2+1], lazy[k]);
lazy[2*k+2] = h(lazy[k*2+2], lazy[k]);
}
dat[k] = g(dat[k],p(lazy[k],len));
lazy[k] = d0;
}
// [a, b)
T update(int a, int b, ll x, int k, int l, int r) {
eval(r-l, k);
if(b <= l || r <= a) return dat[k];
if(a <= l && r <= b) {
lazy[k] = h(lazy[k], x);
return g(dat[k], p(lazy[k],r-l));
}
return dat[k] = f(update(a, b, x, 2*k+1, l, (l+r)/2),
update(a, b, x, 2*k+2, (l+r)/2, r));
}
T update(int a, int b, ll x) { return update(a, b, x, 0, 0, n); }
// [a, b)
T query(int a, int b, int k, int l, int r) {
eval(r-l, k);
if(a <= l && r <= b) return dat[k];
bool left = !((l+r)/2 <= a || b <= l), right = !(r <= 1 || b <= (l+r)/2);
if(left&&right) return f(query(a, b, 2*k+1, l, (l+r)/2), query(a, b, 2*k+2, (l+r)/2, r));
if(left) return query(a, b, 2*k+1, l, (l+r)/2);
return query(a, b, 2*k+2, (l+r)/2, r);
}
T query(int a, int b) { return query(a, b, 0, 0, n); }
// デバッグ出力
void debug() {
cout << "---------------------" << endl;
int cnt = 0;
for(int i=1; i<=n; i*=2) {
REP(j, i) {cout << "(" << dat[cnt] << "," << lazy[cnt] << ") "; cnt++;}
cout << endl;
}
cout << "---------------------" << endl;
}
};
signed main(void)
{
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
VV<int> v(n, V<int>(3));
V<int> x(m);
REP(i, n) {
cin >> v[i][1] >> v[i][2] >> v[i][0];
v[i][0]--, v[i][1]--, v[i][2]--;
}
REP(i, m) cin >> x[i], x[i]--;
auto f = [&](int a, int b){return max(a,b);};
auto g = [&](int a, int b){return b==INT_MAX?a:b;};
lazySegTree<int,int> seg(1e5, f, g, g, INT_MAX, INT_MAX);
V<int> a(1e5);
iota(ALL(a), 0);
seg.build(a);
sort(ALL(v));
REP(i, n) {
int mid = (v[i][1]+v[i][2]) / 2;
// [v[i][1], mid] [mid+1, v[i][2]]
seg.update(v[i][1], mid+1, seg.query(v[i][1], v[i][1]+1));
seg.update(mid+1, v[i][2]+1, seg.query(v[i][2], v[i][2]+1));
}
REP(i, m) {
cout << seg.query(x[i], x[i]+1)+1 << endl;
}
return 0;
}
|