#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,bmi,bmi2")
#include<iostream>
#include<vector>
#include<utility>
#include<map>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<pair<int, int>> vec(n + 1);
for(int i = 1; i <= n; i++) cin >> vec[i].first >> vec[i].second;
int q;
cin >> q;
vector<int> maxi(n + 1);
for(int i = 1; i <= n; i++) maxi[i] = max(maxi[i - 1], vec[i].second);
while(q--){
int a;
cin >> a;
int r = vec[1].second, ans = 1;
while(r < n && ans <= n + 1){
r = maxi[r];
ans++;
}
if(ans == n + 2) cout << "-1\n";
else cout << ans << "\n";
}
}
// g++ -std=gnu++20 pC.cpp -o run -Wall -Wextra -fsanitize=undefined -fsanitize=address
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
21 ms |
5056 KB |
Output is correct |
5 |
Correct |
21 ms |
5192 KB |
Output is correct |
6 |
Correct |
22 ms |
5220 KB |
Output is correct |
7 |
Correct |
17 ms |
4432 KB |
Output is correct |
8 |
Correct |
16 ms |
3676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
21 ms |
5056 KB |
Output is correct |
5 |
Correct |
21 ms |
5192 KB |
Output is correct |
6 |
Correct |
22 ms |
5220 KB |
Output is correct |
7 |
Correct |
17 ms |
4432 KB |
Output is correct |
8 |
Correct |
16 ms |
3676 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |