#include using namespace std; // #include // using namespace atcoder; /* alias */ using ull = unsigned long long; using ll = long long; using pii = pair; using pll = pair; using vi = vector; using vll = vector; using vd = vector; using vs = vector; using vb = vector; using vpii = vector>; using vpll = vector>; using vvi = vector>; using vvll = vector>; using vvd = vector>; using vvs = vector>; using vvb = vector>; template using min_priority_queue = priority_queue, greater>; /* define */ #define MOD 998244353 // #define MOD 1000000007 #define INF (1LL << 60) #define elif else if #define pb push_back #define pf push_front #define fi first #define se second #define all(obj) (obj).begin(), (obj).end() #define YESNO(bool) cout << (bool ? "YES\n" : "NO\n") #define YesNo(bool) cout << (bool ? "Yes\n" : "No\n") #define yesno(bool) cout << (bool ? "yes\n" : "no\n") template bool chmax(T &a, const T &b) {if(a bool chmin(T &a, const T &b) {if(b= 0; i--) #define rrepd(i, n) for(ll i = (n); i >= 1; i--) #define fore(i, a) for(auto &i: a) /* vector */ template T vmax(vector &array){ T ret = array[0]; for(T a: array) chmax(ret, a); return ret; } template T vmin(vector &array){ T ret = array[0]; for(T a: array) chmin(ret, a); return ret; } template T sum(vector &array){ T ret = 0; for(T a:array) ret += a; return ret; } template void list_set(vector &array){ sort(all(array)); array.erase(unique(all(array)),array.end()); } template int bisect_left(vector &array, T key){ return lower_bound(all(array),key) - array.begin(); } template int bisect_right(vector &array, T key){ return upper_bound(all(array),key) - array.begin(); } /* string */ ll string_to_ll(string n){ ll ret = 0, k = 1; while(n.length() > 0){ ret += k * (n.back() - '0'); n.pop_back(); k *= 10; } return ret; } string ll_to_string(ll n){ string ret = ""; while(n > 0){ ret.pb((n % 10) + '0'); n /= 10; } reverse(all(ret)); return ret; } struct popopo{ popopo(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(15); }; } popopoppo; // n = 1,...,N に対して、n % A < B を満たすものの数 ll Count_of_n_mod_A_less_than_B(ll N, ll A, ll B){ return N / A * min(A, B) + min(N % A, B - 1); } /* IN/OUT */ int scan() { return getchar(); } void scan(int &a) { cin >> a; } void scan(long long &a) { cin >> a; } void scan(char &a) { cin >> a; } void scan(double &a) { cin >> a; } void scan(string &a) { cin >> a; } template void scan(pair &p) { scan(p.first), scan(p.second); } template void scan(vector &); template void scan(vector &a) { for(auto &i : a) scan(i); } void IN(){} template void IN(Head& head, Tail &...tail){ scan(head); IN(tail...); } #define INT(...) int __VA_ARGS__; IN(__VA_ARGS__) #define LL(...) ll __VA_ARGS__; IN(__VA_ARGS__) #define STR(...) string __VA_ARGS__; IN(__VA_ARGS__) #define VEC(type, name, size) vector name(size); IN(name) #define VECS(type, name, size) vector name(size + 1); for(int i = 1; i <= size; i++) scan(name[i]) void OUT(){ cout << "\n"; } template void output(T a){ cout << a; } template void output(vector v){ for(int i = 0; i < v.size(); i++) cout << v[i] << (i == v.size() - 1 ? "" : " "); } template void OUT(const Head &head, const Tail &...tail) { output(head); if(sizeof...(tail)) cout << " "; OUT(tail...); } void FLASH(){ cout << endl; } template void FLASH(const Head &head, const Tail &...tail) { output(head); if(sizeof...(tail)) cout << " "; FLASH(tail...); } template struct CumulativeSum { int n; vector data; bool builded = false; CumulativeSum(int n) : n(n), data(n + 1) {} CumulativeSum(const vector &v) : n(v.size()), data(n + 1) { for (int i = 0; i < n; i++) { data[i + 1] = v[i]; } } void build() { for (int i = 0; i < n; i++) { data[i + 1] += data[i]; } builded = true; } T sum(int r) { if (!builded) build(); assert(0 <= r && r <= n); return data[r]; } T sum(int l, int r) { assert(0 <= l && l <= r && r <= n); return sum(r) - sum(l); } }; template class dynamic_segtree { public: dynamic_segtree(size_t n) : n(n), root(nullptr) {} void set(size_t p, S x) { assert(p < n); set(root, 0, n, p, x); } S get(size_t p) const { assert(p < n); return get(root, 0, n, p); } S prod(size_t l, size_t r) const { assert(l <= r && r <= n); return prod(root, 0, n, l, r); } S all_prod() const { return root ? root->product : e(); } void reset(size_t l, size_t r) { assert(l <= r && r <= n); return reset(root, 0, n, l, r); } template size_t max_right(size_t l) const { return max_right(l, [](S x) { return f(x); }); } template size_t max_right(size_t l, const F& f) const { assert(l <= n); S product = e(); assert(f(product)); return max_right(root, 0, n, l, f, product); } template size_t min_left(size_t r) const { return min_left(r, [](S x) { return f(x); }); } template size_t min_left(size_t r, const F& f) const { assert(r <= n); S product = e(); assert(f(product)); return min_left(root, 0, n, r, f, product); } private: struct node; using node_ptr = std::unique_ptr; struct node { size_t index; S value, product; node_ptr left, right; node(size_t index, S value) : index(index), value(value), product(value), left(nullptr), right(nullptr) {} void update() { product = op(op(left ? left->product : e(), value), right ? right->product : e()); } }; const size_t n; node_ptr root; void set(node_ptr& t, size_t a, size_t b, size_t p, S x) const { if (!t) { t = std::make_unique(p, x); return; } if (t->index == p) { t->value = x; t->update(); return; } size_t c = (a + b) >> 1; if (p < c) { if (t->index < p) std::swap(t->index, p), std::swap(t->value, x); set(t->left, a, c, p, x); } else { if (p < t->index) std::swap(p, t->index), std::swap(x, t->value); set(t->right, c, b, p, x); } t->update(); } S get(const node_ptr& t, size_t a, size_t b, size_t p) const { if (!t) return e(); if (t->index == p) return t->value; size_t c = (a + b) >> 1; if (p < c) return get(t->left, a, c, p); else return get(t->right, c, b, p); } S prod(const node_ptr& t, size_t a, size_t b, size_t l, size_t r) const { if (!t || b <= l || r <= a) return e(); if (l <= a && b <= r) return t->product; size_t c = (a + b) >> 1; S result = prod(t->left, a, c, l, r); if (l <= t->index && t->index < r) result = op(result, t->value); return op(result, prod(t->right, c, b, l, r)); } void reset(node_ptr& t, size_t a, size_t b, size_t l, size_t r) const { if (!t || b <= l || r <= a) return; if (l <= a && b <= r) { t.reset(); return; } size_t c = (a + b) >> 1; reset(t->left, a, c, l, r); reset(t->right, c, b, l, r); t->update(); } template size_t max_right(const node_ptr& t, size_t a, size_t b, size_t l, const F& f, S& product) const { if (!t || b <= l) return n; if (f(op(product, t->product))) { product = op(product, t->product); return n; } size_t c = (a + b) >> 1; size_t result = max_right(t->left, a, c, l, f, product); if (result != n) return result; if (l <= t->index) { product = op(product, t->value); if (!f(product)) return t->index; } return max_right(t->right, c, b, l, f, product); } template size_t min_left(const node_ptr& t, size_t a, size_t b, size_t r, const F& f, S& product) const { if (!t || r <= a) return 0; if (f(op(t->product, product))) { product = op(t->product, product); return 0; } size_t c = (a + b) >> 1; size_t result = min_left(t->right, c, b, r, f, product); if (result != 0) return result; if (t->index < r) { product = op(t->value, product); if (!f(product)) return t->index + 1; } return min_left(t->left, a, c, r, f, product); } }; using S = ll; S op(S a, S b) { return a + b; } S e() { return 0; } int main() { LL(N); vll L(N), A(N); rep(i, N - 1) { LL(l, a); L[i + 1] = l; A[i + 1] = a - 1; } vll memo(N, -1); memo[0] = 1; // memo[i] := 技 i を覚えるのに最小のレベル auto lev = [&](auto &&self, ll i) -> ll { if (memo[i] == -2) { memo[i] = INF; return INF; } if (memo[i] != -1) return memo[i]; memo[i] = -2; ll v = self(self, A[i]); memo[i] = max(v, L[i]); return memo[i]; }; dynamic_segtree seg(1000000100); rep(i, N) { ll v = lev(lev, i); if (v == INF) { continue; } ll now = seg.get(v); seg.set(v, now + 1); } LL(Q); while (Q--) { LL(t); if (t == 1) { LL(x); ll ans = seg.prod(0, x + 1); OUT(ans); } else { LL(y); y--; ll v = lev(lev, y); if (v == INF) { v = -1; } OUT(v); } } }