#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long int ll; typedef pair Pii; const ll mod = 998244353; template struct prop_segtree { int n; vector data; vector propFlag; prop_segtree(const int s) { init(s); } prop_segtree(const int s, const T u) { init(s); for (int i = 0; i < s; i++) { data[i+n-1] = u; } for (int i = n-2; i >= 0; i--) { data[i] = 0; } } prop_segtree(const vector &v) { int s = v.size(); init(s); for (int i = 0; i < s; i++) { data[i+n-1] = v[i]; } for (int i = n-2; i >= 0; i--) { data[i] = 0; } } void init(const int s) { n = 1; while (n < s) n <<= 1; data = vector(2*n-1); propFlag = vector(2*n-1); } void propagate(int p, int a, int b) { if (propFlag[p]) { if (b - a > 1) { data[p*2+1] += data[p]; data[p*2+2] += data[p]; propFlag[p*2+1] = true; propFlag[p*2+2] = true; data[p] = 0; } propFlag[p] = false; } } void update(int l, int r, T v, int p = 0, int a = 0, int b = -1) { if (b < 0) b = n; // init // propagate value propagate(p, a, b); if (r <= a || b <= l) return; // out of range if (l <= a && b <= r) { // fully covered data[p] += v; propFlag[p] = true; propagate(p, a, b); } else { update(l, r, v, p*2+1, a, (a + b) / 2); // left update(l, r, v, p*2+2, (a + b) / 2, b); // right } return; } T query(int x, T p = 0, int a = 0, int b = -1) { if (b < 0) b = n; // init // propagate value propagate(p, a, b); if (b - a == 1) return data[p];// reached to bottom if (x < (a + b) / 2) return query(x, p*2+1, a, (a + b) / 2); // left else return query(x, p*2+2, (a + b) / 2, b); // right } }; struct query { int type; string x; int t, l, r; }; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector> xlr(n); for (int i = 0; i < n; i++) { cin >> get<0>(xlr[i]) >> get<1>(xlr[i]) >> get<2>(xlr[i]); } int q; cin >> q; vector que(q); for (int i = 0; i < q; i++) { query qu; cin >> qu.type; if (qu.type == 1) { cin >> qu.x >> qu.t; } else if (qu.type == 2) { cin >> qu.t; } else if (qu.type == 3) { cin >> qu.x >> qu.l >> qu.r; } que[i] = qu; } unordered_set time_in_query_set; for (auto &[_, l, r]: xlr) { time_in_query_set.insert(l); time_in_query_set.insert(r + 1); } for (auto &qu: que) { if (qu.type == 3) { time_in_query_set.insert(qu.l); time_in_query_set.insert(qu.r + 1); } } vector time_in_query_vector; for (auto &x: time_in_query_set) time_in_query_vector.push_back(x); sort(time_in_query_vector.begin(), time_in_query_vector.end()); int time_index_num = time_in_query_vector.size(); unordered_map time_index; for (int i = 0; i < time_index_num; i++) time_index[time_in_query_vector[i]] = i; // for query #2 prop_segtree room_people_count(time_index_num); for (auto &[_, l, r]: xlr) { int l_idx = time_index[l]; int r_idx = time_index[r + 1]; room_people_count.update(l_idx, r_idx, 1); } // for query #1 unordered_map> people_room_info; for (auto &[x, l, r]: xlr) { people_room_info[x].emplace(l, r); } vector ans; for (auto &qu: que) { if (qu.type == 1) { auto it = people_room_info[qu.x].lower_bound(make_pair(qu.t, 2e9)); if (it == people_room_info[qu.x].begin()) { ans.push_back("No"); } else { it--; int r = it->second; if (qu.t <= r) ans.push_back("Yes"); else ans.push_back("No"); } } else if (qu.type == 2) { int t_idx = distance(time_in_query_vector.begin(), upper_bound(time_in_query_vector.begin(), time_in_query_vector.end(), qu.t)) - 1; if (t_idx < 0) ans.push_back("0"); else ans.push_back(to_string(room_people_count.query(t_idx))); } else if (qu.type == 3) { int l_idx = time_index[qu.l]; int r_idx = time_index[qu.r + 1]; room_people_count.update(l_idx, r_idx, 1); people_room_info[qu.x].emplace(qu.l, qu.r); } } for (auto &x: ans) cout << x << endl; return 0; }