#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, q;
pair<int, int> a[200005];
int32_t main() {
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;
cin >> q;
while (q--) {
int x; cin >> x;
int ptr = a[x].second, ans = 1;
pair<int, int> mx = {0, 0};
for (int i = x + 1; i <= a[x].second; i++)
mx = max(mx, {a[i].second, i});
bool b = 1;
while (ptr < n) {
int v = mx.first, idx = mx.second;
ptr = v, ans++;
if (idx == a[idx].second && idx != n) { b = 0; break; }
for (int i = idx + 1; i <= a[idx].second; i++)
mx = max(mx, {a[i].second, i});
}
if (ptr == n && b) cout << ans << '\n';
else cout << -1 << '\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... |