제출 #838680

#제출 시각아이디문제언어결과실행 시간메모리
838680skittles1412Event Hopping (BOI22_events)C++17
10 / 100
1572 ms3012 KiB
#include "bits/extc++.h" using namespace std; template <typename T, typename... U> void dbgh(const T& t, const U&... u) { cerr << t; ((cerr << " | " << u), ...); cerr << endl; } #ifdef DEBUG #define dbg(...) \ cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \ dbgh(__VA_ARGS__) #else #define dbg(...) #define cerr \ if (false) \ cerr #endif #define endl "\n" #define long int64_t #define sz(x) int(std::size(x)) void solve() { int n, q; cin >> n >> q; vector<pair<int, int>> arr(n); for (auto& [l, r] : arr) { cin >> l >> r; } while (q--) { int u, v; cin >> u >> v; u--; v--; if (u == v) { cout << 0 << endl; continue; } int ql = arr[v].first, qr = arr[v].second, ans = 0; while (ql > arr[u].second) { int n_opt = 1e9; for (auto& [l, r] : arr) { if (ql <= r && r <= qr) { n_opt = min(n_opt, l); } } if (n_opt >= ql) { break; } ans++; ql = n_opt; } if (ql <= arr[u].second && arr[u].second <= qr) { ans++; cout << ans << endl; } else { cout << "impossible" << endl; } } } int main() { cin.tie(nullptr); cin.exceptions(ios::failbit); ios_base::sync_with_stdio(false); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...