#include #include using namespace std; using namespace atcoder; typedef long long ll; #define rep(i, n) for (int i = 0; i < n; i++) #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) struct LazySegmentTree { private: int n; vector node, lazy; public: LazySegmentTree(vector v) { int sz = (int)v.size(); n = 1; while(n < sz) n *= 2; node.resize(2*n-1); lazy.resize(2*n-1, 0); for(int i=0; i=0; i--) node[i] = node[i*2+1] + node[i*2+2]; } void eval(int k, int l, int r) { if(lazy[k] != 0) { node[k] += lazy[k]; if(r - l > 1) { lazy[2*k+1] += lazy[k] / 2; lazy[2*k+2] += lazy[k] / 2; } lazy[k] = 0; } } void add(int a, int b, ll x, int k=0, int l=0, int r=-1) { if(r < 0) r = n; eval(k, l, r); if(b <= l || r <= a) return; if(a <= l && r <= b) { lazy[k] += (r - l) * x; eval(k, l, r); } else { add(a, b, x, 2*k+1, l, (l+r)/2); add(a, b, x, 2*k+2, (l+r)/2, r); node[k] = node[2*k+1] + node[2*k+2]; } } ll getsum(int a, int b, int k=0, int l=0, int r=-1) { if(r < 0) r = n; eval(k, l, r); if(b <= l || r <= a) return 0; if(a <= l && r <= b) return node[k]; ll vl = getsum(a, b, 2*k+1, l, (l+r)/2); ll vr = getsum(a, b, 2*k+2, (l+r)/2, r); return vl + vr; } }; int main(){ ll n ; cin >> n ; set it ; set> L[n+1] ; vector> V[n] ; map mp ; vector> vt ; ll a = 1 ; rep(i,n){ string x; ll l, r ; cin >> x >> l >> r ; if( mp[x] == 0 ) mp[x] = a++ ; L[mp[x]].insert({l,r}) ; it.insert(l) ; it.insert(r) ; } ll q ; cin >> q ; // クエリ先読み rep(i,q){ ll t ; cin >> t ; string x ; ll num = 0 , time = 0 , l = 0 , r = 0 ; if( t == 1 ){ cin >> x ; cin >> time ; num = mp[x] ; } if( t == 2 ){ cin >> time ; it.insert(time) ; } if( t == 3 ){ cin >> x >> l >> r ; num = mp[x] ; it.insert(l) ; it.insert(r) ; } vt.push_back({t,num,time,l,r}) ; } LazySegmentTree seg( vector(it.size(), 0) ); rep(i,n){ for( auto [l,r] : L[i] ){ auto p = it.lower_bound(l) ; auto q = it.lower_bound(r) ; ll pd = distance(it.begin(),p) ; ll qd = distance(it.begin(),q) ; seg.add(pd,qd+1,1) ; } } rep(i,q){ auto [t,x,time,l,r] = vt[i] ; if( t == 1 ){ auto p = L[x].lower_bound({time,time}) ; pair pw = *p ; if( pw.first <= time && time <= pw.second ){ cout << "Yes" << endl ; } else{ cout << "No" << endl ; } } if( t == 2 ){ auto p = it.lower_bound(time) ; ll pd = distance(it.begin(),p) ; cout << seg.getsum(pd,pd+1) << endl ; } if( t == 3 ){ auto p = it.lower_bound(l) ; auto q = it.lower_bound(r) ; ll pd = distance(it.begin(),p) ; ll qd = distance(it.begin(),q) ; seg.add(pd,qd+1,1) ; // 区間に加算してクエリ2を処理する。 L[x].insert({l,r}) ; } } }