#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;
		priority_queue<pair<int, int>> pq;
		for (int i = x + 1; i <= a[x].second; i++)
			pq.emplace(a[i].second, i);
		while (!pq.empty() && ptr < n) {
			int v = pq.top().first, idx = pq.top().second;
			pq.pop();
			ptr = v, ans++;
			for (int i = idx + 1; i <= a[idx].second; i++)
				pq.emplace(a[i].second, i);
		}
		if (ptr == n) 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... |