#include #include using namespace std; //座標圧縮 template vector comp(vector &vec) { int siz = vec.size(); vector tmp = vec; sort(tmp.begin(), tmp.end()); tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end()); vector ret(siz); for(int i = 0; i < siz; i++) ret[i] = lower_bound(tmp.begin(), tmp.end(), vec[i]) - tmp.begin(); return ret; } int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector X(N); vector L(N), R(N); vector v; map> mp; map> lr; for(int i = 0; i < N; i++) { cin >> X[i] >> L[i] >> R[i]; v.emplace_back(L[i]); v.emplace_back(R[i] + 1); if(mp.count(X[i]) == 0) { mp[X[i]] = {L[i]}; } else { mp[X[i]].insert(L[i]); } lr[X[i]][L[i]] = R[i]; } int Q; cin >> Q; vector> query(Q); for(int i = 0; i < Q; i++) { int T; cin >> T; if(T == 1) { string x; int t; cin >> x >> t; query[i] = make_tuple(1, x, t, -1); v.emplace_back(t); v.emplace_back(-1); } if(T == 2) { int t; cin >> t; query[i] = make_tuple(2, ".", t, -1); v.emplace_back(t + 1); v.emplace_back(-1); } if(T == 3) { string x; int l, r; cin >> x >> l >> r; query[i] = make_tuple(3, x, l, r); v.emplace_back(l); v.emplace_back(r + 1); } } int M = 2 * (N + Q)+ 5; v = comp(v); atcoder::fenwick_tree fw(M); for(int i = 0; i < 2 * N; i++) { fw.add(v[2 * i], 1); fw.add(v[2 * i + 1], -1); } for(int i = 0; i < Q; i++) { tuple tup = query[i]; int T = get<0>(tup); if(T == 1) { string x = get<1>(tup); int t = get<2>(tup); if(mp.count(x) == 0) { cout << "No\n"; } else { set &vl = mp[x]; bool ok = true; auto it = vl.upper_bound(t); if(it == vl.begin()) { cout << "No\n"; } else { int li = *prev(it); int ri = lr[x][li]; if(li <= t && t <= ri) { cout << "Yes\n"; } else { cout << "No\n"; } } } } if(T == 2) { int t = v[2 * N + 2 * i]; cout << fw.sum(0, t + 1) << '\n'; } if(T == 3) { string x = get<1>(tup); int l = get<2>(tup); int r = get<3>(tup); if(mp.count(x) == 0) { mp[x] = {l}; } else { mp[x].insert(l); } lr[x][l] = r; fw.add(v[2 * N + 2 * i], 1); fw.add(v[2 * N + 2 * i + 1], -1); } } return 0; }