Submission #721655

#TimeUsernameProblemLanguageResultExecution timeMemory
721655MDSProEvent Hopping (BOI22_events)C++14
0 / 100
63 ms11668 KiB
#include "bits/stdc++.h" using namespace std; int main(){ cin.tie(0)->sync_with_stdio(0); int n,q; cin >> n >> q; vector<tuple<int,int,int>> ev; for(int i = 0; i < n; ++i){ int x,y; cin >> x >> y; ev.emplace_back(x,y,i+1); } sort(ev.begin(),ev.end()); vector<int> nw_order(n+1); vector<int> left(n+1),right(n+1); for(int i = 0; i < n; ++i) { left[i] = get<0>(ev[i]); right[i] = get<1>(ev[i]); nw_order[get<2>(ev[i])] = i; } vector<vector<int>> nxt(20,vector<int>(n+1)); nxt[0][n-1] = nxt[0][n] = n; int r = 0; for(int i = 0; i < n-1; ++i){ while(r+1 < n && left[r+1] <= right[i]) r++; nxt[0][i] = r; } for(int i = 1; i < 20; ++i) { for(int j = 0; j <= n; ++j){ nxt[i][j] = nxt[i-1][nxt[i-1][j]]; } } auto get = [&](int x, int y){ int cur = 0; for(int i = 19; i >= 0; --i){ if(nxt[i][x] <= y) { cur |= (i<<1); x = nxt[i][x]; } } return cur; }; while(q--){ int a,b; cin >> a >> b; a = nw_order[a]; b = nw_order[b]; if(a == b) cout << "0\n"; else if(a > b) cout << "impossible\n"; else cout << get(a,b) << '\n'; } }
#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...