#include "bits/stdc++.h"
using namespace std;
template<typename T>
using V = vector<T>;
using vi = V<int>;
using pi = pair<int,int>;
#define f first
#define s second
#define F0R(i, n) for(int i = 0; i < n;i++)
#define FOR(i,a, n) for(int i = a; i < n;i++)
#define pb push_back
#define all(x) begin(x), end(x)
#define each(x, y) for(auto &x : y)
constexpr int INF = 1e9 + 2;
pi binarySearch(V<pi> &stack, int point) {
auto it = std::upper_bound(stack.begin(), stack.end(), make_pair(point,INF)); // Point to before or at point
if (it == stack.begin()) return {0,0};
it--;
return {it - stack.begin() + 1, it->s};
}
int getImp(V<pi> &stack) {
return (stack.empty() ? 0 : stack.back().s);
}
#define ckmax(a,b) a = max(a,b)
int main() {
int n, q; cin >> n >> q;
V<pi> edges;
F0R(i, n) {
int a, b; cin >> a >> b;
edges.pb({a,b});
}
F0R(i, q) {
int a, b; cin >> a >> b;
a--;
b--;
int point = edges[a].s;
int ans = 0;
while (point < edges[b].f) {
int bestNext = point;
ans++;
F0R(j, n) {
if (edges[j].f <= point) ckmax(bestNext, edges[j].s);
}
if (bestNext == point) break;
point = bestNext;
}
if (a == b) {
cout << "0\n";
continue;
}
if (point < edges[b].f || point > edges[b].s) {
cout << "impossible\n";
continue;
}
cout << ans + 1 << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Execution timed out |
1587 ms |
3392 KB |
Time limit exceeded |
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 |
84 ms |
444 KB |
Output is correct |
4 |
Correct |
10 ms |
344 KB |
Output is correct |
5 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
6 |
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 |
84 ms |
444 KB |
Output is correct |
4 |
Correct |
10 ms |
344 KB |
Output is correct |
5 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
6 |
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 |
84 ms |
444 KB |
Output is correct |
4 |
Correct |
10 ms |
344 KB |
Output is correct |
5 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1552 ms |
3272 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Execution timed out |
1587 ms |
3392 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |