Submission #893452

#TimeUsernameProblemLanguageResultExecution timeMemory
893452vjudge1Event Hopping 2 (JOI21_event2)C++17
39 / 100
586 ms283568 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, k; cin >> n >> k; vector <int> L(n), R(n); for ( int i = 0; i < n; i++ ){ cin >> L[i] >> R[i]; } { // compression vector <int> p_; for ( int i = 0; i < n; i++ ){ p_.pb(L[i]); p_.pb(R[i]); } sort(all(p_)); p_.resize(unique(all(p_)) - p_.begin()); auto get = [&](int x){ return lower_bound(all(p_), x) - p_.begin() + 1; }; for ( int i = 0; i < n; i++ ){ L[i] = get(L[i]); R[i] = get(R[i]); } } int m = n * 2; vector <vector<int>> quL(m + 1), quR(m + 1); for ( int i = 0; i < n; i++ ){ quR[R[i]].pb(L[i]); quL[L[i]].pb(R[i]); } auto DpL = [&](int x){ vector <int> dpL(m + 2); for ( int i = x; i > 0; i-- ){ dpL[i] = dpL[i + 1]; for ( auto &j: quL[i] ){ if ( j <= x ){ chmax(dpL[i], dpL[j] + 1); } } } return dpL; }; auto dpL = DpL(m); if ( dpL[1] < k ){ return cout << "-1\n", 0; } if ( n > 3e3 ){ int lst = -1; for ( int i = 0; i < n && k > 0; i++ ){ if ( lst <= L[i] && dpL[R[i]] >= k - 1 ){ cout << i + 1 << ln; k--; lst = R[i]; } } exit(0); } vector <vector<int>> dp(m + 1, vector <int> (m + 2)); for ( int i = 1; i <= m; i++ ){ auto q = DpL(i); for ( int j = 1; j <= m; j++ ){ dp[j][i] = q[j]; } } vector <ar<int,2>> rng; rng.pb({1, m}); for ( int i = 0; i < m && k > 0; i++ ){ int cnt = 0, j = -1, it = 0; for ( auto &[l, r]: rng ){ cnt += dp[l][r]; if ( l <= L[i] && r >= R[i] ){ j = it; } it++; } if ( j != -1 ){ auto [l, r] = rng[j]; if ( cnt - dp[l][r] + dp[l][L[i]] + dp[R[i]][r] + 1 >= k ){ cout << i + 1 << ln; k--; rng[j] = {l, L[i]}; rng.pb({R[i], r}); } } } 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...