Submission #387330

#TimeUsernameProblemLanguageResultExecution timeMemory
387330SeDunionEvent Hopping 2 (JOI21_event2)C++17
100 / 100
722 ms88296 KiB
#include<bits/stdc++.h> #ifndef LOCAL #define cerr if(false)cerr #endif // LOCAL using namespace std; using ll = long long; const int N = 1e6 + 66; const int LOG = 20; struct el { int l, r, i; } e[N]; int n, k; int sp[N][LOG]; int cnt(int l, int r) { int res = 0; for (int j = LOG - 1 ; j >= 0 ; -- j) { if (sp[l][j] <= r) { res += (1 << j); l = sp[l][j]; } } return res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin >> n >> k; vector<int>vals; for (int i = 1 ; i <= n ; ++ i) { cin >> e[i].l >> e[i].r; e[i].i = i; vals.emplace_back(e[i].l); vals.emplace_back(e[i].r); } sort(vals.begin(), vals.end()); for (int i = 1 ; i <= n ; ++ i) { e[i].l = lower_bound(vals.begin(), vals.end(), e[i].l) - vals.begin(); e[i].r = lower_bound(vals.begin(), vals.end(), e[i].r) - vals.begin(); } for (int j = 0 ; j < LOG ; ++ j) for (int i = 0 ; i < N ; ++ i) sp[i][j] = N - 1; for (int i = 1 ; i <= n ; ++ i) { sp[e[i].l][0] = min(sp[e[i].l][0], e[i].r); } for (int i = N - 1 ; i > 0 ; -- i) { sp[i - 1][0] = min(sp[i - 1][0], sp[i][0]); } for (int j = 1 ; j < LOG ; ++ j) { for (int i = 0 ; i < N ; ++ i) { sp[i][j] = sp[sp[i][j - 1]][j - 1]; } for (int i = N - 1 ; i > 0 ; -- i) { sp[i - 1][j] = min(sp[i - 1][j], sp[i][j]); } } set<pair<int,int>>s={{0, N - 2}}; int cur = cnt(0, N - 2); if (cur < k) { cout << -1; return 0; } vector<int>ans; for (int i = 1 ; i <= n ; ++ i) { int L = e[i].l, R = e[i].r; auto it = s.upper_bound(pair{L, N}); it--; int l = it->first, r = it->second; if (l <= L && R <= r) { if (cur + 1 - cnt(l, r) + cnt(l, L) + cnt(R, r) >= k) { cur = cur + 1 - cnt(l, r) + cnt(l, L) + cnt(R, r); ans.emplace_back(i); s.erase(it); s.insert({l, L}); s.insert({R, r}); } } if ((int)ans.size() == k) { break; } } sort(ans.begin(), ans.end()); for (int i : ans) cout << i << "\n"; //assert((int)ans.size() == k); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...