Submission #656515

#TimeUsernameProblemLanguageResultExecution timeMemory
656515LoboEvent Hopping (BOI22_events)C++17
0 / 100
1572 ms13768 KiB
#include<bits/stdc++.h> using namespace std; const long long inf = (long long) 1e18 + 10; const int inf1 = (int) 1e9 + 10; #define int long long #define dbl long double #define endl '\n' #define sc second #define fr first #define mp make_pair #define pb push_back #define all(x) x.begin(), x.end() const int maxn = 1e5+10; int n, q, lf[maxn], rg[maxn], sq[maxn], eq[maxn], ansq[maxn], nx[maxn]; vector<int> qrys[maxn]; void solve() { cin >> n >> q; vector<pair<pair<int,int>,int>> ord; // first smaller rg and smaller lf for(int i = 1; i <= n; i++) { cin >> lf[i] >> rg[i]; ord.pb(mp(mp(rg[i],lf[i]),i)); } sort(all(ord)); for(int i = 1; i <= q; i++) { cin >> sq[i] >> eq[i]; qrys[eq[i]].pb(i); } for(int i = 1; i <= n; i++) { nx[i] = -1; } for(auto X : ord) { int i = X.sc; for(int j = 1; j <= n; j++) { //from j to i if(lf[i] <= rg[j] && rg[j] < rg[i] && j != i) { nx[j] = i; } if(rg[i] == rg[j] && lf[j] < lf[i]) { nx[j] = i; } } // cout << i << endl; for(auto id : qrys[i]) { // cout << " " << id << endl; int j = sq[id]; if(i == j) { ansq[id] = 0; break; } if(rg[j] == rg[i]) { ansq[id] = 1; break; } int cnt = 0; while(j != -1) { j = nx[j]; cnt++; if(j == i) break; } if(j == -1) { ansq[id] = -1; } else { ansq[id] = cnt; } } } for(int i = 1; i <= q; i++) { if(ansq[i] == -1) cout << "impossible" << endl; else cout << ansq[i] << endl; } } int32_t main() { ios::sync_with_stdio(false); cin.tie(0); // freopen("in.in", "r", stdin); // freopen("out.out", "w", stdout); int tt = 1; // cin >> tt; while(tt--) { 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...