#include using namespace std; template struct BinaryIndexedTree{ int N; vector BIT; BinaryIndexedTree(const int &N): N(N), BIT(N + 1, 0){ } T get(int i){ return sum(i + 1) - sum(i); } void add(int i, T x){ i++; while(i <= N){ BIT[i] += x; i += i & -i; } } T sum(int i) const { T ans = 0; while(i > 0){ ans += BIT[i]; i -= i & -i; } return ans; } T sum(int L, int R) const { return sum(R) - sum(L); } int lower_bound(T x) const { if(x <= 0){ return 0; }else{ int v = 0, r = 1; while(r < N) r = r << 1; for(int len = r; len > 0; len = len >> 1){ if(v + len < N && BIT[v + len] < x){ x -= BIT[v + len]; v += len; } } return v; } } int upper_bound(T x) const { if(x < 0){ return 0; }else{ int v = 0, r = 1; while(r <= N) r = r << 1; for(int len = r; len > 0; len = len >> 1){ if(v + len <= N && BIT[v + len] <= x){ x -= BIT[v + len]; v += len; } } return v; } } T operator [](int i) const { return sum(i, i + 1); } }; template struct compress{ vector sorted, compressed; compress(const vector& vec){ int n = vec.size(); compressed.resize(n); for(T x : vec){ sorted.emplace_back(x); } sort(sorted.begin(), sorted.end()); sorted.erase(unique(sorted.begin(), sorted.end()), sorted.end()); for(int i = 0; i < n; ++i){ compressed[i] = lower_bound(sorted.begin(), sorted.end(), vec[i]) - sorted.begin(); } } int get(const T& x) const{ return lower_bound(sorted.begin(), sorted.end(), x) - sorted.begin(); } T inv(const T& x) const{ return sorted[x]; } size_t size() const{ return sorted.size(); } vector getCompressed() const{ return compressed; } }; int conv(string s){ int res = 0, n = s.size(); int p = 1; for(int i = 0; i < n; i++){ res += (s[i] - 'A' + 1) * p; p *= 27; } return res; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; map> time; vector X(N); vector XC(N), L(N), R(N); vector XCC = {0}; for(int i = 0; i < N; i++){ cin >> X[i] >> L[i] >> R[i]; XC[i] = conv(X[i]); time[0].push_back(L[i]); time[0].push_back(R[i] + 1); time[XC[i]].push_back(L[i]); time[XC[i]].push_back(R[i] + 1); XCC.push_back(XC[i]); } int Q; cin >> Q; vector> query(Q); for(int i = 0; i < Q; i++){ int type; cin >> type; if(type == 1){ string x; int t; cin >> x >> t; int xc = conv(x); query[i] = {type, xc, t, 0}; time[xc].push_back(t); XCC.push_back(xc); }else if(type == 2){ int t; cin >> t; query[i] = {type, t, 0, 0}; time[0].push_back(t); }else{ string x; int l, r; cin >> x >> l >> r; int xc = conv(x); query[i] = {type, xc, l, r}; time[0].push_back(l); time[0].push_back(r + 1); time[xc].push_back(l); time[xc].push_back(r + 1); XCC.push_back(xc); } } compress XCCcomp(XCC); int M = XCCcomp.size(); vector> comp(M, compress(vector(0))); vector> BIT(M, BinaryIndexedTree(0)); for(auto [k, x] : time){ int idx = XCCcomp.get(k); comp[idx] = compress(x); BIT[idx] = BinaryIndexedTree(comp[idx].size()); } for(int i = 0; i < N; i++){ BIT[0].add(comp[0].get(L[i]), 1); BIT[0].add(comp[0].get(R[i] + 1), -1); int idx = XCCcomp.get(XC[i]); BIT[idx].add(comp[idx].get(L[i]), 1); BIT[idx].add(comp[idx].get(R[i] + 1), -1); } for(int i = 0; i < Q; i++){ auto [type, a, b, c] = query[i]; if(type == 1){ int idx = XCCcomp.get(a); if(BIT[idx].sum(0, comp[idx].get(b) + 1) == 1){ cout << "Yes" << endl; }else{ cout << "No" << endl; } }else if(type == 2){ cout << BIT[0].sum(0, comp[0].get(a) + 1) << endl; }else{ int idx = XCCcomp.get(a); BIT[0].add(comp[0].get(b), 1); BIT[0].add(comp[0].get(c + 1), -1); BIT[idx].add(comp[idx].get(b), 1); BIT[idx].add(comp[idx].get(c + 1), -1); } } }