#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 1e5;
struct event {
int l, r, i;
};
int main() {
int n, m;
cin >> n >> m;
vector<event> ev(n), og;
map<int,int> comp;
int _i = 0;
for (auto& [s, e, i] : ev) {
cin >> s >> e;
comp[s] = comp[e] = 0;
i = _i++;
}
int k = 0;
for (auto& mp : comp)
mp.second = k++;
for (auto& [s, e, i] : ev)
s = comp[s], e = comp[e];
og = ev;
sort(ev.begin(), ev.end(), [&](auto& a, auto& b) {
return a.r == b.r ? a.l < b.l : a.r < b.r ;
});
//for (auto[a,b,c] : ev) cout << a << ' ' << b << ' ' << c <<'\n';
while (m--) {
int s, e;
cin >> s >> e;
s--;e--;
if (s == e) {
cout << "0\n";
continue;
}
int si = 0, ei = 0;
for (int j = 0; j < n; j++) {
if (ev[j].i == s) si = j;
if (ev[j].i == e) ei = j;
}
int res = 0;
bool found = 0;
int left = ev[ei].l;
set<int> st;
for (int j = n-1; j >= 0; j--) {
auto [l,r,_i] = ev[j];
if (r > ev[ei].r) continue;
if (r < left) {
if (st.empty()) break;
left = *st.begin();
if (r < left) break;
st.clear();
res++;
}
if (j == si) {
res++;
found = 1;
break;
}
st.insert(l);
continue;
}
if (found) cout << res << '\n';
else cout << "impossible\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1561 ms |
8772 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
5 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
312 KB |
Output is correct |
5 |
Correct |
3 ms |
368 KB |
Output is correct |
6 |
Correct |
4 ms |
312 KB |
Output is correct |
7 |
Correct |
6 ms |
476 KB |
Output is correct |
8 |
Correct |
5 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
5 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
312 KB |
Output is correct |
5 |
Correct |
3 ms |
368 KB |
Output is correct |
6 |
Correct |
4 ms |
312 KB |
Output is correct |
7 |
Correct |
6 ms |
476 KB |
Output is correct |
8 |
Correct |
5 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
5 ms |
340 KB |
Output is correct |
13 |
Correct |
4 ms |
316 KB |
Output is correct |
14 |
Correct |
4 ms |
340 KB |
Output is correct |
15 |
Correct |
4 ms |
340 KB |
Output is correct |
16 |
Correct |
6 ms |
468 KB |
Output is correct |
17 |
Correct |
5 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
316 KB |
Output is correct |
19 |
Execution timed out |
1588 ms |
1220 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
5 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
312 KB |
Output is correct |
5 |
Correct |
3 ms |
368 KB |
Output is correct |
6 |
Correct |
4 ms |
312 KB |
Output is correct |
7 |
Correct |
6 ms |
476 KB |
Output is correct |
8 |
Correct |
5 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
6 ms |
372 KB |
Output is correct |
13 |
Correct |
3 ms |
340 KB |
Output is correct |
14 |
Correct |
3 ms |
308 KB |
Output is correct |
15 |
Correct |
4 ms |
368 KB |
Output is correct |
16 |
Correct |
6 ms |
468 KB |
Output is correct |
17 |
Correct |
6 ms |
440 KB |
Output is correct |
18 |
Correct |
2 ms |
212 KB |
Output is correct |
19 |
Correct |
447 ms |
7980 KB |
Output is correct |
20 |
Correct |
309 ms |
7980 KB |
Output is correct |
21 |
Correct |
596 ms |
10236 KB |
Output is correct |
22 |
Correct |
294 ms |
10188 KB |
Output is correct |
23 |
Correct |
673 ms |
18456 KB |
Output is correct |
24 |
Correct |
1029 ms |
14036 KB |
Output is correct |
25 |
Correct |
91 ms |
3892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1588 ms |
7328 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1561 ms |
8772 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |