#include #include using namespace std; using namespace atcoder; //using mint = modint1000000007; //const int mod = 1000000007; //using mint = modint998244353; //const int mod = 998244353; //const int INF = 1e9; //const long long LINF = 1e18; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n-1); i >= 0; --i) #define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define endl "\n" #define P pair template inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } template struct value_compression : vector { bool built = false; using VS = vector; using VS::VS; value_compression(vector v = {}) : vector(move(v)) {} void build() { sort(this->begin(), this->end()); this->erase(unique(this->begin(), this->end()), this->end()); built = true; } template void convert(T first, T last) { assert(built); for (; first != last; ++first) *first = (*this)(*first); } int operator()(S x) { assert(built); return lower_bound(this->begin(), this->end(), x) - this->begin(); } void clear() { this->clear(); built = false; } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector> inp(n); value_compression name; value_compression time; for (auto&[x, l, r] : inp) { cin >> x >> l >> r, l--; name.emplace_back(x); time.emplace_back(l); time.emplace_back(r); } int q; cin >> q; struct Q { int type; string x; int l, r; }; vectorquery(q); for (auto &[type, x, l, r] : query) { cin >> type; if (1 == type) { cin >> x >> l; l--; name.push_back(x); time.push_back(l); } else if (2 == type) { cin >> l; l--; time.push_back(l); } else { cin >> x >> l >> r; l--; name.push_back(x); time.push_back(l); time.push_back(r); } } name.build(); time.build(); vector> memo(name.size()); fenwick_tree ft(time.size()); for (auto&[x, l, r] : inp) { int p = name(x); l = time(l); r = time(r); memo[p][r] = l; ft.add(l, 1); ft.add(r, -1); } for (auto &[type, x, l, r] : query) { if (1 == type) { int p = name(x); l = time(l); auto it = memo[p].upper_bound(l); bool ok = it != memo[p].end() && it->second <= l; cout << (ok ? "Yes\n" : "No\n"); } else if (2 == type) { l = time(l); cout << ft.sum(0, l + 1) << endl; } else { int p = name(x); l = time(l); r = time(r); memo[p][r] = l; ft.add(l, 1); ft.add(r, -1); } } return 0; }