#include using namespace std; #define rep(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++) #define rrep(i, a, b) for (int i = (int)(b) - 1; (i) >= (int)(a); (i)--) #define all(v) v.begin(), v.end() typedef long long ll; template using V = vector; template using VV = vector>; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); constexpr char endl = '\n'; int n,q; cin >> n; map>> mp; V stin, stout; rep(i,0,n) { string name; int inT, outT; cin >> name >> inT >> outT; mp[name].push_back({inT, -1}); mp[name].push_back({outT, 1}); stin.push_back(inT); stout.push_back(outT); sort(all(mp[name])); } sort(all(stin)); sort(all(stout)); cin >> q; rep(i,0,q) { int cmd; cin >> cmd; if (cmd == 1) { string name; int t; cin >> name >> t; if (mp.find(name) == mp.end()) { cout << "No" << endl; continue; } auto mpst = mp[name]; auto pos = lower_bound(all(mpst), make_pair(t,0)); if ((*pos).second == 1) cout << "Yes" << endl; else cout << "No" << endl; } else if (cmd == 2) { int t; cin >> t; int in = lower_bound(all(stin), t+1) - stin.begin(); int out = lower_bound(all(stout), t) - stout.begin(); cout << in - out << endl; } else { string name; int tin, tout; cin >> name >> tin >> tout; mp[name].push_back({tin,-1}); mp[name].push_back({tout,1}); sort(all(mp[name])); stin.push_back(tin); sort(all(stin)); stout.push_back(tout); sort(all(stout)); } } return 0; }