Submission #807426

#TimeUsernameProblemLanguageResultExecution timeMemory
807426rnl42Passport (JOI23_passport)C++14
0 / 100
2063 ms62632 KiB
#include <bits/stdc++.h> using namespace std; #define int long long string to_string(string s) { return s; } template <typename T> string to_string(T v) { bool first = true; string res = "["; for (const auto &x : v) { if (!first) res += ", "; first = false; res += to_string(x); } res += "]"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } void dbg_out() { cout << endl; } template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << to_string(H); dbg_out(T...); } #ifdef DEBUG #define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #else #define dbg(...) #endif constexpr int INF = 1e9; vector<pair<vector<int>,int>> tree; int tree_shift = 0; int N, Q; vector<int> L, R; vector<int> X; vector<vector<int>> dp; struct Adjacency { int itree, ivec = 0; Adjacency(int u) { itree = tree_shift+u; correctidx(); } inline void correctidx() { while (itree != 0 && ivec >= tree[itree].first.size()) { ivec = 0; itree >>= 1; } } Adjacency begin() { return Adjacency(itree-tree_shift); } Adjacency end() { return Adjacency(-tree_shift); } void operator++() { ivec++; correctidx(); } bool operator!=(const Adjacency& other) const { return itree != other.itree || ivec != other.ivec; } int operator*() const { return tree[itree].first[ivec]; } }; void bfs(vector<int>& dist) { vector<vector<int>> q(N+10); for (int i = 0; i < (int)dist.size(); i++) { if (dist[i] < INF) q[dist[i]].push_back(i); } for (int d = 0; d < (int)q.size(); d++) { for (int u : q[d]) { if (dist[u] != d) continue; for (int v : Adjacency(u)) { if (u == v) continue; if (dist[u]+1 < dist[v]) { dist[v] = dist[u]+1; q[dist[v]].push_back(v); } } } } } signed main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> N; L.resize(N), R.resize(N); tree_shift = 1<<__lg(2*N-1); tree.resize(2*tree_shift); for (int i = 0; i < N; i++) { cin >> L[i] >> R[i], L[i]--, R[i]--; for (int l = tree_shift+L[i], r = tree_shift+R[i]+1; l < r; l >>= 1, r >>= 1) { if (l&1) tree[l++].first.push_back(i); if (r&1) tree[--r].first.push_back(i); } } cin >> Q; X.resize(Q); for (int i = 0; i < Q; i++) { cin >> X[i], X[i]--; } vector<int> ddeb(N, INF); ddeb[0] = 0; bfs(ddeb); ddeb[0]++; vector<int> dfin(N, INF); dfin[N-1] = 0; bfs(dfin); dfin[N-1]++; vector<int> ans(N); for (int i = 0; i < N; i++) { ans[i] = ddeb[i]+dfin[i]; } bfs(ans); for (int i = 0; i < N; i++) if (ans[i] >= INF) ans[i] = -1; else ans[i]--; for (int i = 0; i < Q; i++) { cout << ans[X[i]] << '\n'; } }

Compilation message (stderr)

passport.cpp: In member function 'void Adjacency::correctidx()':
passport.cpp:53:35: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         while (itree != 0 && ivec >= tree[itree].first.size()) {
      |                              ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...