제출 #420259

#제출 시각아이디문제언어결과실행 시간메모리
420259amoo_safarEvent Hopping 2 (JOI21_event2)C++17
100 / 100
301 ms25508 KiB
// vaziat meshki-ghermeze ! #include <bits/stdc++.h> #define pb push_back #define F first #define S second #define all(x) x.begin(), x.end() #define debug(x) cerr << #x << " : " << x << '\n' using namespace std; typedef long long ll; typedef long double ld; typedef string str; typedef pair<ll, ll> pll; const ll Mod = 1000000007LL; const int N = 2e5 + 10; const ll Inf = 2242545357980376863LL; const int Log = 20; int nx[Log][N]; int mn[N]; int l[N], r[N]; int Solve(int lq, int rq){ int ans = 0; for(int lg = Log - 1; lg >= 0; lg--){ if(nx[lg][lq] <= rq){ lq = nx[lg][lq]; ans += (1 << lg); } } return ans; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; vector<int> V; for(int i = 1; i <= n; i++){ cin >> l[i] >> r[i]; V.pb(l[i]); V.pb(r[i]); } sort(all(V)); V.resize(unique(all(V)) - V.begin()); int m = V.size(); fill(mn, mn + m + 1, m); for(int i = 1; i <= n; i++){ l[i] = lower_bound(all(V), l[i]) - V.begin(); r[i] = lower_bound(all(V), r[i]) - V.begin(); mn[l[i]] = min(mn[l[i]], r[i]); } for(int i = m - 1; i >= 0; i--) mn[i] = min(mn[i], mn[i + 1]); for(int i = 0; i <= m; i++) nx[0][i] = mn[i]; for(int lg = 0; lg + 1 < Log; lg++) for(int i = 0; i <= m; i++) nx[lg + 1][i] = nx[lg][ nx[lg][i] ]; if(Solve(0, m - 1) < k) return cout << "-1\n", 0; int sm = Solve(0, m - 1); set< pair<int, int> > st; st.insert({0, m - 1}); vector<int> pk; for(int i = 1; i <= n; i++){ auto it = st.upper_bound({l[i], Inf}); if(it == st.begin()) continue; it --; auto seg = *it; if(seg.S < r[i]) continue; int ft = sm - Solve(seg.F, seg.S) + Solve(seg.F, l[i]) + Solve(r[i], seg.S) + 1; if(ft < k) continue; st.erase(seg); if(seg.F != l[i]) st.insert({seg.F, l[i]}); if(seg.S != r[i]) st.insert({r[i], seg.S}); sm = ft; pk.pb(i); } for(int i = 0; i < k; i++) cout << pk[i] << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...