제출 #1177372

#제출 시각아이디문제언어결과실행 시간메모리
1177372SulAPassport (JOI23_passport)C++20
0 / 100
2094 ms12044 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define all(a) a.begin(), a.end() using namespace std; using namespace __gnu_pbds; using namespace chrono; #define ordered_set tree<int, null_type, less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> int dist[200000], n; int l[200000], r[200000]; int bfs(int start) { fill(dist, dist + n, 1e9); dist[start] = 0; queue<int> q; q.push(start); set<int> unv; for (int i = 0; i < n; i++) if (i != start) unv.insert(i); while (!q.empty()) { int u = q.front(); q.pop(); while (true) { auto it = unv.lower_bound(l[u]); if (it == unv.end() || *it > r[u]) break; dist[*it] = dist[u] + 1; q.push(*it); unv.erase(it); } } int ans = *max_element(dist, dist + n); return ans == 1e9 ? -1 : ans; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n; for (int i = 0; i < n; cin >> l[i] >> r[i], l[i]--, r[i++]--); for (int i = 0; i < n; i++) bfs(i); int q; cin >> q; while (q--) { int s; cin >> s; s--; cout << bfs(s) << "\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...