#include <bits/stdc++.h>
#define rep(a,b,c) for(auto a = (b); a != (c); a++)
#define repD(a,b,c) for(auto a = (b); a != (c); a--)
#define repIn(a, b) for(auto& a : (b))
#define repIn2(a, b, c) for(auto& [a, b] : (c))
constexpr bool dbg = 1;
#define DEBUG if constexpr(dbg)
#define DC DEBUG std::cerr
#define eol std::endl
#define ll long long
#define pb push_back
using namespace std;
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int n;
cin >> n;
vector<pair<int, int>> v(n);
rep(i, 0, n) cin >> v[i].first >> v[i].second;
int q;
cin >> q;
rep(i, 0, q) {
int l, r;
cin >> l;
r = l;
if(l == 1) {
int ans = 0;
vector<int> maxPref;
rep(j, 0, n) maxPref.pb(max(maxPref.size() ? maxPref.back() : 0, v[j].second));
while(r != n && r < maxPref[r - 1]) {
ans++;
r = maxPref[r - 1];
}
if(r != n) ans = -1;
cout << ans << '\n';
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |