#include #include using namespace std; using ll = long long; struct E { int type, time, uid, qid; }; int main() { int N; cin >> N; map ID; auto get_id = [&](string x) -> int { if(ID.count(x)) return ID[x]; int res = ID.size(); ID[x] = res; return res; }; vector es; for(int i = 0; i < N; i++) { string x; int L, R; cin >> x >> L >> R; int uid = get_id(x); es.push_back(E{1, L, uid, -1}); es.push_back(E{2, R+1, uid, -1}); } int Q; cin >> Q; for(int i = 0; i < Q; i++) { int t; cin >> t; if(t == 1) { string x; int time; cin >> x >> time; int uid = get_id(x); es.emplace_back(E{3, time, uid, i}); } else if(t == 2) { int time; cin >> time; es.emplace_back(E{4, time, -1, i}); } else { string x; int L, R; cin >> x >> L >> R; int uid = get_id(x); es.emplace_back(E{1, L, uid, i}); es.emplace_back(E{2, R+1, uid, i}); } } sort(es.begin(), es.end(), [](const E& l, const E& r) { if(l.time != r.time) return (l.time < r.time); return (l.type < r.type); }); set> id_set; atcoder::fenwick_tree bt(Q+1); vector> ans; for(const auto& e : es) { if(e.type == 1) { id_set.insert({e.uid, -e.qid}); bt.add(e.qid + 1, 1); } else if(e.type == 2) { id_set.erase({e.uid, -e.qid}); bt.add(e.qid + 1, -1); } else if(e.type == 3) { auto it = id_set.lower_bound({e.uid, -e.qid}); if(e.qid != -1) { if(it->first == e.uid) ans.emplace_back(e.qid, 1, 1); else ans.emplace_back(e.qid, 1, 0); } } else { if(e.qid != -1) ans.emplace_back(e.qid, 2, bt.sum(0, e.qid + 1)); } } sort(ans.begin(), ans.end()); for(const auto& [_, t, v] : ans) { if(t == 1) cout << (v ? "Yes" : "No") << '\n'; else cout << v << '\n'; } }