#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; const int MAX_N = 300000; class RangeAddQuery { public: vector bit0; vector bit1; RangeAddQuery(int N = MAX_N) { bit0.resize(N + 1); bit1.resize(N + 1); } void update(int l, int r, ll x) { add(bit0, l, -x * (l - 1)); add(bit1, l, x); add(bit0, r + 1, x * r); add(bit1, r + 1, -x); } ll get(int i) { return get(i, i); } ll get(int l, int r) { ll res = 0; res += sum(bit0, r) + sum(bit1, r) * r; res -= sum(bit0, l - 1) + sum(bit1, l - 1) * (l - 1); return res; } private: void add(vector &b, int i, ll v) { while (i <= MAX_N) { b[i] += v; i += i & -i; } } ll sum(vector &b, int i) { ll s = 0; while (i > 0) { s += b[i]; i -= i & -i; } return s; } }; int main() { int N; cin >> N; string X[N]; int L[N]; int R[N]; set S; set names; for (int i = 0; i < N; ++i) { cin >> X[i] >> L[i] >> R[i]; names.insert(X[i]); S.insert(L[i]); S.insert(R[i]); } int Q; cin >> Q; int types[Q]; string X2[Q]; int T[Q]; int L2[Q]; int R2[Q]; for (int i = 0; i < Q; ++i) { int type; cin >> type; types[i] = type; if (type == 1) { cin >> X2[i] >> T[i]; S.insert(T[i]); } else if (type == 2) { cin >> T[i]; S.insert(T[i]); } else { cin >> X2[i] >> L2[i] >> R2[i]; names.insert(X2[i]); S.insert(L2[i]); S.insert(R2[i]); } } map pos; int idx = 1; for (int s : S) { pos[s] = idx; ++idx; } map memo; RangeAddQuery raq; for (int i = 0; i < N; ++i) { string x = X[i]; int l = pos[L[i]]; int r = pos[R[i]]; raq.update(l, r, 1); memo[x].update(l, r, 1); } for (int i = 0; i < Q; ++i) { int type = types[i]; if (type == 1) { string x = X2[i]; int t = pos[T[i]]; if (memo[x].get(t)) { cout << "Yes" << endl; } else { cout << "No" << endl; } } else if (type == 2) { int t = pos[T[i]]; cout << raq.get(t) << endl; } else { string x = X2[i]; int l = pos[L2[i]]; int r = pos[R2[i]]; raq.update(l, r, 1); memo[x].update(l, r, 1); } } return 0; }