제출 #599053

#제출 시각아이디문제언어결과실행 시간메모리
599053VanillaEvent Hopping (BOI22_events)C++17
0 / 100
68 ms2476 KiB
#include <bits/stdc++.h> using namespace std; typedef long long int64; const int maxn = 1e5 + 2; struct nd { int x; int y; int idx; bool operator < (const nd& oth) const { return make_pair(x, y) < make_pair(oth.x, oth.y); } } a [maxn]; int ps [maxn]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n,q; cin >> n >> q; for (int i = 0; i < n; i++){ cin >> a[i].x >> a[i].y; a[i].idx = i; } sort(a, a + n); for (int i = 0; i < n; i++){ ps[a[i].idx] = i; } while (q--){ int x,y; cin >> x >> y; x = ps[x - 1], y = ps[y - 1]; if (x > y) { cout << "impossible\n"; continue; } cout << y - x << "\n"; // cout << x << " " << y << "\n"; // int r = a[x].y, rs = 0; // int mx = -1; // while (1) { // if (x == y) { // rs++; // break; // } // else if (a[x].x <= r) mx = max(a[x].y, mx); // else { // if (a[x].x <= mx) { // rs++; // r = mx; // // mx = a[x].y; // } // else { // rs = -1; // break; // } // } // cout << a[x].x << " " << a[x].y << " " << r << " " << mx << " " << rs << "\n"; // x++; // } // cout << (rs == -1 ? "impossible" : to_string(rs)) << "\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...