이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 1e5;
int main() {
int n, m;
cin >> n >> m;
vector<pair<int,int>> ev(n), og;
for (auto& [s, e] : ev) cin >> s >> e;
og = ev;
sort(ev.begin(), ev.end());
ev.emplace_back(inf, inf);
while (m--) {
int s, e;
cin >> s >> e;
s--;e--;
multiset<int,greater<>> right;
int sr = og[s].second;
int ans{}, found{};
if (og[e].second <= og[s].first) {
cout << "impossible\n";
continue;
}
if (s == e) {
cout << "0\n";
continue;
}
if (max(og[s].first, og[e].first) < min(og[s].second, og[e].second)) {
cout << "1\n";
continue;
}
for (auto [l, r] : ev) {
if (r < sr) continue;
if (sr < l) {
if (og[e].first <= sr && sr <= og[e].second) {
found = 1;
break;
}
ans++;
sr = *right.begin();
}
right.insert(r);
}
if (found)cout << ans+1 << '\n';
else cout << "impossible\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |