#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define int long long
const int N = 2e5 + 69;
int n, l[N], r[N], q, p[N];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
cin >> n;
for (int i = 1;i <= n;i++) {
cin >> l[i] >> r[i];
p[i] = max(p[i - 1], r[i]);
}
cin >> q;
for (int i = 1;i <= q;i++) {
int x;
cin >> x;
int ans = 1, ptr = r[1];
while (ptr != n) {
if (ptr == p[r[ptr]]) {
ans = -1;
break;
}
ptr = p[ptr];
++ans;
}
cout << ans << '\n';
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
24 ms |
5008 KB |
Output is correct |
5 |
Correct |
22 ms |
4928 KB |
Output is correct |
6 |
Correct |
24 ms |
7512 KB |
Output is correct |
7 |
Correct |
19 ms |
6740 KB |
Output is correct |
8 |
Correct |
17 ms |
6224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
24 ms |
5008 KB |
Output is correct |
5 |
Correct |
22 ms |
4928 KB |
Output is correct |
6 |
Correct |
24 ms |
7512 KB |
Output is correct |
7 |
Correct |
19 ms |
6740 KB |
Output is correct |
8 |
Correct |
17 ms |
6224 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |