제출 #893812

#제출 시각아이디문제언어결과실행 시간메모리
893812vjudge1Event Hopping 2 (JOI21_event2)C++17
100 / 100
188 ms42412 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; const int inf = m + 1; vector <int> qu(m + 1, inf); for ( int i = 0; i < n; i++ ){ chmin(qu[L[i]], R[i]); } vector <vector<int>> up(20, vector <int> (m + 2, inf)); for ( int i = m; i > 0; i-- ){ up[0][i] = min(qu[i], up[0][i + 1]); } for ( int i = 1; i < 20; i++ ){ for ( int j = 1; j <= m; j++ ){ up[i][j] = up[i - 1][up[i - 1][j]]; } } auto dp = [&](int l, int r){ int cnt = 0; for ( int i = 19; i >= 0; i-- ){ if ( up[i][l] <= r ){ l = up[i][l]; cnt |= 1 << i; } } return cnt; }; int tot = dp(1, m); if ( tot < k ){ return cout << "-1", 0; } set <pair<int,int>> st{{1, m}}; vector <int> ans; for ( int i = 0; i < n; i++ ){ auto it = prev(st.lower_bound({L[i] + 1, -1})); auto [l, r] = *it; if ( r >= R[i] ){ int nxt = tot - dp(l, r) + dp(l, L[i]) + dp(R[i], r) + 1; if ( nxt >= k ){ swap(nxt, tot); ans.pb(i); st.erase(it); st.insert({l, L[i]}); st.insert({R[i], r}); } } } for ( int i = 0; i < k; i++ ){ cout << ans[i] + 1 << ln; } 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...