제출 #1094717

#제출 시각아이디문제언어결과실행 시간메모리
1094717crafticatEvent Hopping (BOI22_events)C++17
0 / 100
1555 ms1492 KiB
#include "bits/stdc++.h" using namespace std; template<typename T> using V = vector<T>; using vi = V<int>; using pi = pair<int,int>; #define f first #define s second #define F0R(i, n) for(int i = 0; i < n;i++) #define FOR(i,a, n) for(int i = a; i < n;i++) #define pb push_back #define all(x) begin(x), end(x) #define each(x, y) for(auto &x : y) constexpr int INF = 1e9 + 2; pi binarySearch(V<pi> &stack, int point) { auto it = std::upper_bound(stack.begin(), stack.end(), make_pair(point,INF)); // Point to before or at point if (it == stack.begin()) return {0,0}; it--; return {it - stack.begin() + 1, it->s}; } int getImp(V<pi> &stack) { return (stack.empty() ? 0 : stack.back().s); } #define ckmax(a,b) a = max(a,b) int main() { int n, q; cin >> n >> q; V<pi> edges; F0R(i, n) { int a, b; cin >> a >> b; edges.pb({a,b}); } F0R(i, q) { int a, b; cin >> a >> b; a--; b--; int point = edges[a].f; int ans = 0; while (point < edges[b].f) { int bestNext = point; ans++; F0R(j, n) { if (edges[j].f <= point) ckmax(bestNext, edges[j].s); } if (bestNext == point) break; point = bestNext; } if (a == b) { cout << "0\n"; continue; } if (point < edges[b].f || point > edges[b].s) { cout << "impossible\n"; continue; } cout << ans + 1 << "\n"; } return 0; }
#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...