#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';
vector ans(n, vector(n, inf));
vector<int> mnl(k, inf);
for (auto [l, r, i] :ev) {
mnl[r] = min(mnl[r], l);
}
for (int ei = n-1; ei >= 0; ei--) {
int res = 0;
int lb = 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 < lb) {
int mn = inf;
for (int i = lb; i < k; i++)
mn = min(mn, mnl[i]);
lb = mn;
if (r < lb) break;
res++;
}
ans[ei][j] = res + 1;
st.insert(l);
}
}
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;
}
if (ans[ei][si] < inf) cout << ans[ei][si] << '\n';
else cout << "impossible\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
543 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |