Submission #978555

#TimeUsernameProblemLanguageResultExecution timeMemory
978555vjudge1Passport (JOI23_passport)C++17
0 / 100
89 ms17080 KiB
#include<bits/stdc++.h> #define sz size() #define ll long long using namespace std; const ll N = 200200; const ll INF = 1e18; void solve() { ll n, Q, i, j, k; cin >> n; ll l[n + 1], r[n + 1]; for(i = 1; i <= n; ++i) cin >> l[i] >> r[i]; cin >> Q; while(Q--) { ll start; cin >> start; ll cl = start, cr = start; vector<ll> d(n + 1, INF); d[start] = 0; multiset<pair<ll, ll>> q; q.insert({0, start}); ll ans = 0; while(q.sz) { auto [x, s] = *q.begin(); q.erase({x, s}); ll ok = 0; for(ll t = l[s]; t < min(cl, s); ++t) { if(d[t] < x + 1) continue; q.erase({d[t], t}); d[t] = x + 1; q.insert({d[t], t}); ok = 1; } cl = min(cl, l[s]); for(ll t = max(s, cr) + 1; t <= r[s]; ++t) { if(d[t] < x + 1) continue; q.erase({d[t], t}); d[t] = x + 1; q.insert({d[t], t}); ok = 1; } ans += ok; cr = max(cr, r[s]); } cout << (ans ? ans : -1) << '\n'; } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); solve(); }

Compilation message (stderr)

passport.cpp: In function 'void solve()':
passport.cpp:10:17: warning: unused variable 'j' [-Wunused-variable]
   10 |     ll n, Q, i, j, k;
      |                 ^
passport.cpp:10:20: warning: unused variable 'k' [-Wunused-variable]
   10 |     ll n, Q, i, j, k;
      |                    ^
#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...