Submission #1086328

#TimeUsernameProblemLanguageResultExecution timeMemory
1086328pemguimnPassport (JOI23_passport)C++14
48 / 100
24 ms31400 KiB
#include <bits/stdc++.h> #define int long long #define pii pair<int, int> using namespace std; const int N = 2e5 + 5, NODE = 8e5 + 5, INF = 2e9 + 7; int n, q, l[N], r[N], ans[N], idn[N]; vector<array<int, 2>> adj[N]; void build(int id = 1, int l = 1, int r = n){ if(l == r){ idn[l] = id; return; } int mid = (l + r) / 2; build(id * 2, l, mid), build(id * 2 + 1, mid + 1, r); adj[id * 2].push_back({id, 0}), adj[id * 2 + 1].push_back({id, 0}); } void add(int id, int tl, int tr, int l, int r, int p){ if(r < tl || tr < l) return; if(l <= tl && tr <= r) { adj[id].push_back({idn[p], 1}); return; } int mid = (tl + tr) / 2; add(id * 2, tl, mid, l, r, p), add(id * 2 + 1, mid + 1, tr, l, r, p); } void dijkstra(vector<int> &d){ priority_queue<array<int, 2>> pq; for(int i = 1; i <= 4 * n; i++){ if(d[i] < 1e9) pq.push({-d[i], i}); } while(!pq.empty()){ auto [c, i] = pq.top(); pq.pop(); c = -c; if(c != d[i]) continue; for(auto [x, w] : adj[i]){ if(d[x] > d[i] + w){ d[x] = d[i] + w; pq.push({-d[x], x}); } } } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; build(1, 1, n); for(int i = 1; i <= n; i++){ cin >> l[i] >> r[i]; add(1, 1, n, l[i], r[i], i); } vector<int> d1(4 * n + 1, INF); d1[idn[1]] = 0; dijkstra(d1); vector<int> d2(4 * n + 1, INF); d2[idn[n]] = 0; dijkstra(d2); vector<int> d3(4 * n + 1, INF); d1[idn[1]] = 1, d2[idn[n]] = 1; for(int i = 1; i <= n; i++){ int x = idn[i]; d3[x] = min(d3[x], d1[x] + d2[x] - 1); } dijkstra(d3); cin >> q; while(q--){ int x; cin >> x; int ans = d3[idn[x]]; if(ans >= 1e9) cout << -1; else cout << ans; cout << '\n'; } return 0; }

Compilation message (stderr)

passport.cpp: In function 'void dijkstra(std::vector<long long int>&)':
passport.cpp:38:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   38 |         auto [c, i] = pq.top(); pq.pop();
      |              ^
passport.cpp:41:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   41 |         for(auto [x, w] : adj[i]){
      |                  ^
#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...