From 5325449d5344a744d80e7920e4d8c1e0c1eede5b Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Wed, 1 Feb 2023 19:35:05 +0800 Subject: [PATCH] =?UTF-8?q?P7561=20[JOISC=202021=20Day2]=20=E9=81=93?= =?UTF-8?q?=E8=B7=AF=E3=81=AE=E5=BB=BA=E8=A8=AD=E6=A1=88=20(Road=20Constru?= =?UTF-8?q?ction)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/101118415 --- Luogu/P7561/P7561.cpp | 96 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 Luogu/P7561/P7561.cpp diff --git a/Luogu/P7561/P7561.cpp b/Luogu/P7561/P7561.cpp new file mode 100644 index 00000000..4b0aab79 --- /dev/null +++ b/Luogu/P7561/P7561.cpp @@ -0,0 +1,96 @@ +#include +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const long long INF = 0x3f3f3f3f'3f3f3f3f; + +int n, k; +std::vector> points; + +bool check(long long x) { + int cnt = 0; + std::queue> q; + std::set> set; + + for (auto o : points) { + while (!q.empty() && q.front().first + x < o.first) { + set.erase({q.front().second, q.front().first}); + q.pop(); + } + + cnt += std::distance(set.lower_bound({o.second - x, -INF}), set.upper_bound({o.second + x, INF})); + + if (cnt >= k) return true; + + set.emplace(o.second, o.first); + q.emplace(o); + } + + return false; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> k; + + for (int i = 1, x, y; i <= n; i++) { + cin >> x >> y; + + points.emplace_back(x + y, x - y); + } + + std::sort(points.begin(), points.end()); + + long long l = 0, + r = INF, + res; + + while (l <= r) { + long long mid = (l + r) >> 1; + + if (check(mid)) { + res = mid; + r = mid - 1; + } else { + l = mid + 1; + } + } + + std::vector ans; + std::queue> q; + std::set> set; + + for (auto o : points) { + while (!q.empty() && q.front().first + res - 1 < o.first) { + set.erase({q.front().second, q.front().first}); + q.pop(); + } + + std::transform( + set.lower_bound({o.second - res + 1, -INF}), + set.upper_bound({o.second + res - 1, INF}), + std::back_inserter(ans), + [&](const std::pair& item) -> long long { + return std::max(std::abs(item.first - o.second), o.first - item.second); + }); + + set.emplace(o.second, o.first); + q.emplace(o); + } + + std::sort(ans.begin(), ans.end()); + ans.resize(k, res); + + for (auto x : ans) cout << x << endl; + + return 0; +}