Submission #888916

#TimeUsernameProblemLanguageResultExecution timeMemory
888916Alihan_8Passport (JOI23_passport)C++17
22 / 100
92 ms111560 KiB
#include <bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() #define ar array #define pb push_back #define ln '\n' #define int long long using i64 = long long; template <class F, class _S> bool chmin(F &u, const _S &v){ bool flag = false; if ( u > v ){ u = v; flag |= true; } return flag; } template <class F, class _S> bool chmax(F &u, const _S &v){ bool flag = false; if ( u < v ){ u = v; flag |= true; } return flag; } const int inf = 1e15 + 1; struct Sparse{ vector <vector<int>> T; vector <int> A; int _s; Sparse(auto &a, int s){ int n = a.size(); T.resize(20); _s = s; A = a; for ( auto &j: A ) j *= s; for ( auto &x: T ) x.resize(n); for ( int i = 0; i < n; i++ ){ T[0][i] = i; } for ( int i = 1; i < 20; i++ ){ int k = 1 << i - 1; for ( int j = 0; j < n; j++ ){ if ( A[T[i - 1][j]] < A[T[i - 1][min(n - 1, j + k)]] ){ T[i][j] = T[i - 1][j]; } else T[i][j] = T[i - 1][min(n - 1, j + k)]; } } } int get(int l, int r){ int lg = __lg(r - l + 1), k = 1 << lg; int u = T[lg][l], v = T[lg][r - k + 1]; return A[u] < A[v] ? u : v; } }; signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector <int> L(n), R(n); for ( int i = 0; i < n; i++ ){ cin >> L[i] >> R[i]; --L[i], --R[i]; } Sparse mn(L, 1), mx(R, -1); int q; cin >> q; vector <int> qu(q), p(q); for ( auto &x: qu ){ cin >> x; --x; } iota(all(p), 0); sort(all(p), [&](int &x, int &y){ return R[qu[x]] - L[qu[x]] > R[qu[y]] - L[qu[y]]; }); vector <unordered_map<int,int>> dp(n); dp[0][n - 1] = 0; auto dfs = [&](auto dfs, int l, int r) -> int{ if ( dp[l].count(r) ){ return dp[l][r]; } int ret = inf, L_ = mn.get(l, r), R_ = mx.get(l, r); if ( R[R_] > r ){ chmin(ret, dfs(dfs, min(L[R_], l), R[R_]) + 1); } if ( L[L_] < l ){ chmin(ret, dfs(dfs, L[L_], max(r, R[L_])) + 1); } return dp[l][r] = ret; }; vector <int> ans(q); for ( auto &i: p ){ int s = qu[i]; ans[i] = dfs(dfs, L[s], R[s]); } for ( auto &x: ans ){ cout << (x == inf ? -1 : x + 1) << ln; } cout << '\n'; }

Compilation message (stderr)

passport.cpp:37:12: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   37 |     Sparse(auto &a, int s){
      |            ^~~~
passport.cpp: In instantiation of 'Sparse::Sparse(auto:23&, long long int) [with auto:23 = std::vector<long long int>]':
passport.cpp:72:19:   required from here
passport.cpp:47:28: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   47 |             int k = 1 << i - 1;
      |                          ~~^~~
#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...