#if !__INCLUDE_LEVEL__ #include __FILE__ using PAIR = pair; template struct fenwick_tree { int _n; V data; fenwick_tree() : _n(0) {} explicit fenwick_tree(int n) : _n(n), data(n) {} void add(int p, U x) {assert(0 <= p && p < _n);p++;while (p <= _n) {data[p - 1] += x;p += p & -p;}} U sum(int l, int r) {assert(0 <= l && l <= r && r <= _n);return sum(r) - sum(l);} U sum(int r) {U s = 0;while (r > 0) {s += data[r - 1];r -= r & -r;}return s;} int lower_bound(U w) { int x = 0, r = 1; while (r < _n) r <<= 1; for (int len = r; len > 0; len >>= 1) { if (x + len <= _n && data[x + len - 1] < w) { w -= data[x + len - 1]; x += len; } } if (x >= _n) return -1; return x; } U inversion(V& a) {_n = *max_element(all(a))+1;U ret = 0; data = V(_n);rep(i,sz(a)) {ret +=i-sum(a[i]);add(a[i],1);}return ret;} }; template struct compress{ vector sorted, compressed; compress(const vector& vec){ int n = vec.size(); compressed.resize(n); for(T x : vec){ sorted.emplace_back(x); } sort(sorted.begin(), sorted.end()); sorted.erase(unique(sorted.begin(), sorted.end()), sorted.end()); for(int i = 0; i < n; ++i){ compressed[i] = lower_bound(sorted.begin(), sorted.end(), vec[i]) - sorted.begin(); } } int get(const T& x) const{return lower_bound(sorted.begin(), sorted.end(), x) - sorted.begin();} T inv(const T& x) const{return sorted[x];} size_t size() const{return sorted.size();} vector getCompressed() const{return compressed;} }; struct Solver { // [a-z]を13文字までなら整数値に変換可能 ll str2id(string s){ ll ret = 0, mul = 1; for(auto e: s) ret += (e - 'a' + 1) * mul, mul *= 27; return ret; } string id2str(ll n) { string ret = ""; while(n > 0) ret += 'a' + (n % 27 - 1), n /= 27; return ret; } void solve() { INT(n); V X(n); V ids(n), L(n), R(n); rep(i,n) cin >> X[i] >> L[i] >> R[i]; rep(i,n) ids[i] = str2id(X[i]); map> time; V xs = {0}; rep(i,n) { time[0].push_back(L[i]); time[0].push_back(R[i]+1); time[ids[i]].push_back(L[i]); time[ids[i]].push_back(R[i]+1); xs.push_back(ids[i]); } INT(q); V> query(q); rep(q) { INT(type); if (type == 1) { STR(x); INT(t); auto id = str2id(x); query[i] = {type, id, t, 0}; time[id].push_back(t); xs.push_back(id); } else if (type == 2) { INT(t); query[i] = {type, t, 0, 0}; time[0].push_back(t); } else { STR(x); INT(l,r); auto id = str2id(x); query[i] = {type, id, l, r}; time[0].push_back(l); time[0].push_back(r+1); time[id].push_back(l); time[id].push_back(r+1); xs.push_back(id); } } sort(all(xs)); compress cxs(xs); dump(xs, cxs.compressed); int m = sz(xs); V> comp(m, compress(V(0))); V> ft(m, fenwick_tree(0)); for(auto [k, x]: time) { int idx = cxs.get(k); comp[idx] = compress(x); ft[idx] = fenwick_tree(comp[idx].size()); } rep(i,n) { ft[0].add(comp[0].get(L[i]), 1); ft[0].add(comp[0].get(R[i]+1), -1); int idx = cxs.get(ids[i]); ft[idx].add(comp[idx].get(L[i]), 1); ft[idx].add(comp[idx].get(R[i]+1), -1); } rep(i,q) { auto [type, a, b, c] = query[i]; if (type == 1) { int idx = cxs.get(a); yes(ft[idx].sum(0, comp[idx].get(b) + 1) == 1); dump(id2str(a)); } else if (type == 2) { dump(comp[0].compressed); print(ft[0].sum(0, comp[0].get(a) + 1)); } else { int idx = cxs.get(a); dump(idx, id2str(a)); int l = b, r = c; ft[0].add(comp[0].get(l), 1); ft[0].add(comp[0].get(r+1), -1); ft[idx].add(comp[idx].get(l), 1); ft[idx].add(comp[idx].get(r+1), -1); } } } } solver; signed main(void){ NO_SYNC_STD; dump(""); #ifdef __OPTIMIZE dump("OPTIMIZE ON"); #endif #ifdef __INTERACTIVE dump("INTERACTIVE MODE"); #endif #ifdef __INCLUDE_ATCODER_LIB dump("INCLUDE ATCODER LIB"); #endif solver.solve(); return 0; } #else // #define __OPTIMIZE // #define __INCLUDE_ATCODER_LIB // #define __INTERACTIVE #define _GLIBCXX_DEQUE_BUF_SIZE 64 #ifdef __OPTIMIZE #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #endif #include #ifdef __INCLUDE_ATCODER_LIB #include using namespace atcoder; #endif using namespace std; #define overload4(a, b, c, d, e, ...) e #define rep1(a) for(decltype(a) i = 0, i##_len = (a); i < i##_len; ++i) #define rep2(i, a) for(decltype(a) i = 0, i##_len = (a); i < i##_len; ++i) #define rep3(i, a, b) for(decltype(b) i = (a), i##_len = (b); i < i##_len; ++i) #define rep4(i, a, b, c) for(decltype(b) i = (a), i##_len = (b); i < i##_len; i += (c)) #define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__) #define rrep1(a) for(decltype(a) i = (a); i--;) #define rrep2(i, a) for(decltype(a) i = (a); i--;) #define rrep3(i, a, b) for(decltype(a) i = (b), i##_len = (a); i-- > i##_len;) #define rrep4(i, a, b, c) for(decltype(a) i = (a)+((b)-(a)-1)/(c)*(c), i##_len = (a); i >= i##_len; i -= c) #define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) ((int)(x).size()) #define yes(s) cout << ((s)?"Yes":"No") << "\n"; #define bit(n) (1LL << ((int)(n))) #define get1bit(x,n) (((x) >> (int)(n)) & 1) #define INF ((1 << 30) - 1) #define INFL (1LL << 60) #define PRECISION std::setprecision(16) #define INT(...) int __VA_ARGS__; input(__VA_ARGS__) #define LL(...) ll __VA_ARGS__; input(__VA_ARGS__) #define STR(...) string __VA_ARGS__; input(__VA_ARGS__) #define LD(...) ld __VA_ARGS__; input(__VA_ARGS__) #define VEC(type, name, size) vector name(size); input(name) #ifdef __INTERACTIVE #define NO_SYNC_STD #define ENDL std::endl #else #define NO_SYNC_STD std::cin.tie(nullptr);ios::sync_with_stdio(false) #define ENDL "\n" #endif #ifdef __LOCAL #include #define dump(...) DUMPOUT << " " << string(#__VA_ARGS__) << ": " << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl << " ", dump_func(__VA_ARGS__) #else #define dump(...) #endif using ll=long long;using ull=unsigned long long;using ld=long double;template using V=vector;template using VV=vector>;template using PQ=priority_queue,greater>; template istream &operator>>(istream &is,complex &v){T x,y; is >> x >> y;v.real(x);v.imag(y);return is;} template istream &operator>>(istream &is,V &v){for(auto&& e:v)is >> e;return is;} template istream &operator>>(istream &is,pair &v){is >> v.first >> v.second;return is;} template istream &operator>>(istream &is,array &v){for(auto&& e:v)is >> e;return is;} template void input(A&&... args){(cin >> ... >> args);} template void print_rest(){cout << ENDL;} template void print_rest(const T& first,const A&... rest){cout << " " << first;print_rest(rest...);} template void print(const T& first,const A&... rest){cout << fixed << PRECISION << first;print_rest(rest...);} template void die(const T& first,const A&... rest){cout << fixed << PRECISION << first;print_rest(rest...);exit(0);} template inline string join(const T& v,string sep=" "){if(v.size() == 0)return "";stringstream ss;for(auto&& e:v)ss << sep << e;return ss.str().substr(sz(sep));} V split(const string &s,char sep=' ') {V ret;stringstream ss(s);string buf;while(getline(ss,buf,sep))ret.push_back(buf);return ret;} template inline string padding(const T& v,int length,char pad=' ',bool left=false){stringstream ss;ss << (left?std::left:std::right) << setw(length) << setfill(pad) << v;return ss.str();} template V make_vec(size_t n,T a){return V(n,a);} template auto make_vec(size_t n,Ts... ts){return V(n,make_vec(ts...));} template inline bool chmax(T& a,T b){if(a inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;} template pair binarysearch(T ng,T ok,T eps,F f,bool sign=false){while(abs(ng-ok)>eps){auto mid=ng+(ok-ng)/2;if(sign^f(mid)){ok=mid;}else{ng=mid;}}return{ng,ok};} template constexpr T cdiv(T x,T y){return (x+y-1)/y;} template constexpr bool between(T a,T x,T b){return(a<=x&&x inline int lower_index(V&a,T x){return (int)distance(a.begin(),lower_bound(all(a),x));} template inline int upper_index(V&a,T x){return (int)distance(a.begin(),upper_bound(all(a),x));} template inline V transposed(V& A){int h=sz(A),w=sz(A[0]);V tA(w);rep(i,h)rep(j,w)tA[j].push_back(A[i][j]);return tA;} template constexpr T pos1d(T y,T x,T h,T w){assert(between(T(0),y,h));assert(between(T(0),x,w));return y*w+x;} template constexpr pair pos2d(T p,T h,T w){T y=p/w,x=p-y*w;assert(between(T(0),y,h));assert(between(T(0),x,w));return{y,x};} template constexpr T sign(T n) {return (n > 0) - (n < 0);} inline string upper(string s) {for(auto&& e: s) e = between('a',e,(char)('z'+1)) ? e - ('a'-'A') : e;return s;} inline string lower(string s) {for(auto&& e: s) e = between('A',e,(char)('Z'+1)) ? e + ('a'-'A') : e;return s;} inline string replace(string s, map &from, V &to) {for (auto&& e: s) e = '0' + (char)(to[from[e]]);return s;} constexpr ll modpow(ll x,ll n,ll m=1152921504606846976LL){ll ret=1;for(;n>0;x=x*x%m,n>>=1)if(n&1)ret=ret*x%m;return ret;} constexpr ll safe_mod(ll x, ll m) {x%=m;if(x<0)x+=m;return x;} constexpr ll keta(ll n, ll base = 10LL) {ll ret = 0; while(n > 0) {n /= base, ret++;} return ret;} constexpr int pcnt(ll x) {return __builtin_popcountll(x);} constexpr int flog(ll x) {return 63 - __builtin_clzll(x);} constexpr int clog(ll x) {return (x==1LL)?0:(64-__builtin_clzll(x-1LL));} constexpr ll nC2(ll n) {return n*(n-1)/2;} constexpr ld deg2rad(ll degree){return (ld)degree * M_PI/180;} const int dx4[4] = {1, 0, -1, 0}; const int dy4[4] = {0, 1, 0, -1}; const int dx6[6] = {1, 0, -1, 0, 1, -1}; const int dy6[6] = {0, 1, 0, -1, 1, -1}; const int dx8[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy8[8] = {0, 1, 0, -1, 1, 1, -1, -1}; #endif