Submission #888630

#TimeUsernameProblemLanguageResultExecution timeMemory
888630vjudge1Passport (JOI23_passport)C++17
6 / 100
90 ms16804 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; } 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]; } vector <int> dp(n, n + 1); int qq, s; cin >> qq >> s; assert(qq == 1); --s; set <int> st; for ( int i = 0; i < n; i++ ){ st.insert(i); } queue <int> q; for ( int i = L[s]; i <= R[s]; i++ ){ dp[i] = 1; q.push(i); st.erase(i); } while ( !q.empty() ){ int u = q.front(); q.pop(); auto it = st.lower_bound(L[u]); vector <int> er; while ( it != st.end() && *it <= R[u] ){ dp[*it] = dp[u] + 1; q.push(*it); er.pb(*it); it = next(it); } for ( auto &x: er ){ st.erase(x); } } int ans = *max_element(all(dp)); if ( ans == n + 1 ){ ans = -1; } cout << ans; cout << '\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...