제출 #745808

#제출 시각아이디문제언어결과실행 시간메모리
745808vjudge1Event Hopping (BOI22_events)C++17
0 / 100
1080 ms8152 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long int; const ll mod = 1e9 + 7; int c[100100], hely[100100]; struct P { int poz, id; bool veg; }; bool cmp(P& lhs, P& rhs){ if(lhs.poz != rhs.poz){ return lhs.poz < rhs.poz; } return lhs.veg < rhs.veg; } int kov[100100] = {0}, be[100100] = {0}; int main(){ int n, q; cin >> n >> q; vector<P> v; for(int i = 1; i <= n; ++i){ int b, e; cin >> b >> e; v.push_back({b, i, false}); v.push_back({e, i, true}); } sort(begin(v), end(v), cmp); set<int> act; for(auto i : v){ if(i.veg){ act.erase(i.id); kov[i.id] = *act.begin(); be[*act.begin()]++; } else{ act.emplace(i.id); } } int ctr = 0; for(int i = 1; i <= n; ++i){ if(be[i] == 0){ ++ctr; int ptr = i, poz = 1; while(ptr != 0){ c[ptr] = ctr; hely[ptr] = poz; ++poz; ptr = kov[ptr]; } } } while(q--){ int a, b; cin >> a >> b; if(c[a] != c[b] || hely[a] > hely[b]){ cout << "impossible" << endl; } else{ cout << hely[b] - hely[a] << endl; } } 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...