#include <bits/stdc++.h>
using namespace std;
struct Event {
int s, e, idx;
};
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int n, q; cin >> n >> q;
vector<Event> events(n);
int j = 0;
for (Event &i : events) {
cin >> i.s >> i.e;
i.idx = ++j;
}
vector<Event> old = events;
sort(events.begin(), events.end(), [&](Event a, Event b) {
if (a.e == b.e) return a.s < b.s;
return a.e < b.e;
});
map<int, pair<int, int>> m;
int segment = 1;
for (int i = 0; i < n; i++) {
if (i && (events[i].s > events[i-1].e || events[i-1].e > events[i].e)) segment++;
m[events[i].idx] = {i, segment};
}
while (q--) {
int a, b; cin >> a >> b;
if (old[a-1].e == old[b-1].e) {
cout << 1 << "\n";
continue;
}
if (m[a].second != m[b].second) {
cout << "impossible\n";
continue;
}
a = m[a].first; b = m[b].first;
if (a > b) cout << "impossible\n";
else cout << b-a << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
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 |
- |
# |
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 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
9488 KB |
Output is correct |
2 |
Correct |
137 ms |
9432 KB |
Output is correct |
3 |
Correct |
223 ms |
9428 KB |
Output is correct |
4 |
Correct |
123 ms |
10008 KB |
Output is correct |
5 |
Incorrect |
176 ms |
9832 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |