Submission #1279183

#TimeUsernameProblemLanguageResultExecution timeMemory
1279183duckindogEvent Hopping 2 (JOI21_event2)C++20
32 / 100
29 ms8804 KiB
#include <bits/stdc++.h> using namespace std; const int N = 100'000 + 10; int n, k; pair<int, int> p[N]; vector<int> rrh; namespace ST { int f[N][17]; void init() { for (int i = 1; i <= (int)rrh.size() + 1; ++i) { for (int j = 0; j <= 16; ++j) f[i][j] = rrh.size() + 1; } for (int i = 1; i <= n; ++i) { const auto& [x, y] = p[i]; f[x][0] = min(f[x][0], y); } for (int i = rrh.size(); i >= 1; --i) { for (int j = 0; j <= 16; ++j) { auto& ret = f[i][j]; ret = min(ret, f[i + 1][j]); if (j) ret = min(ret, f[f[i][j - 1]][j - 1]); } } } int get(int l, int r) { int ret = 0; for (int i = 16; i >= 0; --i) { if (f[l][i] <= r) { ret += (1 << i); l = f[l][i]; } } return ret; } } int32_t main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> p[i].first >> p[i].second; for (int i = 1; i <= n; ++i) { rrh.push_back(p[i].first); rrh.push_back(p[i].second); } sort(rrh.begin(), rrh.end()); rrh.erase(unique(rrh.begin(), rrh.end()), rrh.end()); for (int i = 1; i <= n; ++i) { auto& [x, y] = p[i]; x = upper_bound(rrh.begin(), rrh.end(), x) - rrh.begin(); y = upper_bound(rrh.begin(), rrh.end(), y) - rrh.begin(); } ST::init(); int total = ST::get(1, rrh.size()); if (total < k) { cout << -1 << '\n'; return 0; } int cnt = 0; set<pair<int, int>> s{{1, rrh.size()}}; for (int i = 1; i <= n; ++i) { const auto& [x, y] = p[i]; int l = -1, r = -1; bool isValid = true; { // check if intersect auto it = s.lower_bound({x + 1, 0}); if (it == s.begin()) isValid = false; else { it = prev(it); if (it->second < y) isValid = false; tie(l, r) = *it; } } if (!isValid) continue; int nTotal = total - ST::get(l, r) + ST::get(l, x) + ST::get(y, r) + 1; if (nTotal < k) continue; s.erase({l, r}); if (l < x) s.insert({l, x}); if (y < r) s.insert({y, r}); total = nTotal; cout << i << "\n"; if (++cnt == k) break; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...