From b363548d85d470ccd262fc2d48ca8f0bed5a90f2 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Wed, 17 Aug 2022 14:01:23 +0800 Subject: [PATCH] P2698 [USACO12MAR]Flowerpot S https://www.luogu.com.cn/record/84127155 --- Luogu/P2698/P2698.cpp | 60 +++++++++++++++++++++++++++++++++++ Luogu/P2698/data/P2698_1.in | 3 ++ Luogu/P2698/data/P2698_1.out | 3 ++ Luogu/P2698/data/P2698_10.in | 3 ++ Luogu/P2698/data/P2698_10.out | 3 ++ Luogu/P2698/data/P2698_2.in | 3 ++ Luogu/P2698/data/P2698_2.out | 3 ++ Luogu/P2698/data/P2698_3.in | 3 ++ Luogu/P2698/data/P2698_3.out | 3 ++ Luogu/P2698/data/P2698_4.in | 3 ++ Luogu/P2698/data/P2698_4.out | 3 ++ Luogu/P2698/data/P2698_5.in | 3 ++ Luogu/P2698/data/P2698_5.out | 3 ++ Luogu/P2698/data/P2698_6.in | 3 ++ Luogu/P2698/data/P2698_6.out | 3 ++ Luogu/P2698/data/P2698_7.in | 3 ++ Luogu/P2698/data/P2698_7.out | 3 ++ Luogu/P2698/data/P2698_8.in | 3 ++ Luogu/P2698/data/P2698_8.out | 3 ++ Luogu/P2698/data/P2698_9.in | 3 ++ Luogu/P2698/data/P2698_9.out | 3 ++ 21 files changed, 120 insertions(+) create mode 100644 Luogu/P2698/P2698.cpp create mode 100644 Luogu/P2698/data/P2698_1.in create mode 100644 Luogu/P2698/data/P2698_1.out create mode 100644 Luogu/P2698/data/P2698_10.in create mode 100644 Luogu/P2698/data/P2698_10.out create mode 100644 Luogu/P2698/data/P2698_2.in create mode 100644 Luogu/P2698/data/P2698_2.out create mode 100644 Luogu/P2698/data/P2698_3.in create mode 100644 Luogu/P2698/data/P2698_3.out create mode 100644 Luogu/P2698/data/P2698_4.in create mode 100644 Luogu/P2698/data/P2698_4.out create mode 100644 Luogu/P2698/data/P2698_5.in create mode 100644 Luogu/P2698/data/P2698_5.out create mode 100644 Luogu/P2698/data/P2698_6.in create mode 100644 Luogu/P2698/data/P2698_6.out create mode 100644 Luogu/P2698/data/P2698_7.in create mode 100644 Luogu/P2698/data/P2698_7.out create mode 100644 Luogu/P2698/data/P2698_8.in create mode 100644 Luogu/P2698/data/P2698_8.out create mode 100644 Luogu/P2698/data/P2698_9.in create mode 100644 Luogu/P2698/data/P2698_9.out diff --git a/Luogu/P2698/P2698.cpp b/Luogu/P2698/P2698.cpp new file mode 100644 index 00000000..6e85abf3 --- /dev/null +++ b/Luogu/P2698/P2698.cpp @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e5 + 5; + +int n, d, ans = std::numeric_limits::max(); +std::pair points[N]; +std::set set; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> d; + + for (int i = 1; i <= n; i++) { + cin >> points[i].first >> points[i].second; + } + + std::sort(points + 1, points + 1 + n, [](auto a, auto b) -> bool { + return a.second < b.second; + }); + + int lst = 1; + for (int i = 1; i <= n; i++) { + int pos = std::upper_bound(points + 1, points + 1 + n, std::make_pair(0, points[i].second - d), [](auto a, auto b) -> bool { + return a.second < b.second; + }) + - points; + + for (int j = lst; j < pos; j++) { + set.insert(points[j].first); + } + + lst = pos; + + auto it1 = set.lower_bound(points[i].first), + it2 = set.upper_bound(points[i].first); + + if (it1 != set.begin()) { + ans = std::min(ans, std::abs(points[i].first - *--it1)); + } + + if (it2 != set.end()) { + ans = std::min(ans, std::abs(points[i].first - *it2)); + } + } + + cout << (ans == std::numeric_limits::max() ? -1 : ans) << endl; + + return 0; +} diff --git a/Luogu/P2698/data/P2698_1.in b/Luogu/P2698/data/P2698_1.in new file mode 100644 index 00000000..3d411105 --- /dev/null +++ b/Luogu/P2698/data/P2698_1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0af0152d58568f977f46db42be1cb05bc0263fbf675ae1d519c8cd668ad11ac5 +size 23 diff --git a/Luogu/P2698/data/P2698_1.out b/Luogu/P2698/data/P2698_1.out new file mode 100644 index 00000000..38118f32 --- /dev/null +++ b/Luogu/P2698/data/P2698_1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:53c234e5e8472b6ac51c1ae1cab3fe06fad053beb8ebfd8977b010655bfdd3c3 +size 2 diff --git a/Luogu/P2698/data/P2698_10.in b/Luogu/P2698/data/P2698_10.in new file mode 100644 index 00000000..2b65590f --- /dev/null +++ b/Luogu/P2698/data/P2698_10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a5a45b82da42a220cd3f0ccb83e1861654571ea70c7dad2bbab5f428475ae44e +size 1373802 diff --git a/Luogu/P2698/data/P2698_10.out b/Luogu/P2698/data/P2698_10.out new file mode 100644 index 00000000..ff5b6160 --- /dev/null +++ b/Luogu/P2698/data/P2698_10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a304662d26d686e1911bfb5933447ac7ddf6358edea469b49e1d65430360740a +size 7 diff --git a/Luogu/P2698/data/P2698_2.in b/Luogu/P2698/data/P2698_2.in new file mode 100644 index 00000000..03510e99 --- /dev/null +++ b/Luogu/P2698/data/P2698_2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3e2513ad79629fdea72c4d650a5fe63cdace774cfc4fcb45b32279bdc84962c9 +size 197 diff --git a/Luogu/P2698/data/P2698_2.out b/Luogu/P2698/data/P2698_2.out new file mode 100644 index 00000000..311c4506 --- /dev/null +++ b/Luogu/P2698/data/P2698_2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ee3aa64bb94a50845d5024cd4bd20202a4567aed5cd5328c0d97e9920775fc28 +size 3 diff --git a/Luogu/P2698/data/P2698_3.in b/Luogu/P2698/data/P2698_3.in new file mode 100644 index 00000000..ad2d8a9d --- /dev/null +++ b/Luogu/P2698/data/P2698_3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ee94a7183a780e418dcd4aad1d40590934fec78bb83c7ce73406c6c0dafce2d0 +size 1918 diff --git a/Luogu/P2698/data/P2698_3.out b/Luogu/P2698/data/P2698_3.out new file mode 100644 index 00000000..6ed9f0e6 --- /dev/null +++ b/Luogu/P2698/data/P2698_3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f174f743b00f3fcc707c98b05e3208bf5c74844705e71ea1c37c4105c7b5a703 +size 4 diff --git a/Luogu/P2698/data/P2698_4.in b/Luogu/P2698/data/P2698_4.in new file mode 100644 index 00000000..e1d85e80 --- /dev/null +++ b/Luogu/P2698/data/P2698_4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e55fd0236ec5787a63b040b334a666aa936022dbcb7dfc29c25b2c12865aab17 +size 9250 diff --git a/Luogu/P2698/data/P2698_4.out b/Luogu/P2698/data/P2698_4.out new file mode 100644 index 00000000..e242c075 --- /dev/null +++ b/Luogu/P2698/data/P2698_4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9ebb26b43da83711e15eb9c29f1f0cfb92e0e526c79d53079c08f9eb98cbf7bd +size 5 diff --git a/Luogu/P2698/data/P2698_5.in b/Luogu/P2698/data/P2698_5.in new file mode 100644 index 00000000..5890fedb --- /dev/null +++ b/Luogu/P2698/data/P2698_5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5b2b52419e932ae486b7f53981e25dbcdf5d057bdb14bf6c80e3a8bec887546a +size 48953 diff --git a/Luogu/P2698/data/P2698_5.out b/Luogu/P2698/data/P2698_5.out new file mode 100644 index 00000000..46407d3d --- /dev/null +++ b/Luogu/P2698/data/P2698_5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:57aa8f86038a1c6785fd1ad2ee2d177b308e0919695a05135c240bf47d8af980 +size 5 diff --git a/Luogu/P2698/data/P2698_6.in b/Luogu/P2698/data/P2698_6.in new file mode 100644 index 00000000..81bc9ae9 --- /dev/null +++ b/Luogu/P2698/data/P2698_6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4f9e55a4c3c26a905b26e3e19d7ccd5259cde376d3591b12e98175003686c4dc +size 200306 diff --git a/Luogu/P2698/data/P2698_6.out b/Luogu/P2698/data/P2698_6.out new file mode 100644 index 00000000..b8f138f7 --- /dev/null +++ b/Luogu/P2698/data/P2698_6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6654ef49c73545848fd9ed802716ab6e231f72da7e29b9560bf74a7ec2e8a173 +size 5 diff --git a/Luogu/P2698/data/P2698_7.in b/Luogu/P2698/data/P2698_7.in new file mode 100644 index 00000000..67859d20 --- /dev/null +++ b/Luogu/P2698/data/P2698_7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a456e8eeb97b33047a9dff40e5c8415c3dcfdaa1fad757bc3118f65ceaafab23 +size 389535 diff --git a/Luogu/P2698/data/P2698_7.out b/Luogu/P2698/data/P2698_7.out new file mode 100644 index 00000000..9ed93804 --- /dev/null +++ b/Luogu/P2698/data/P2698_7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cd12044fe2e0af2777882012815de742a35912d5fc7ae48565f1f3b6f50a47ba +size 5 diff --git a/Luogu/P2698/data/P2698_8.in b/Luogu/P2698/data/P2698_8.in new file mode 100644 index 00000000..24518f6c --- /dev/null +++ b/Luogu/P2698/data/P2698_8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d1ec352b4e14a176f836abb7df6208bf516a9119b2fbba07fb21e993a7f5dd77 +size 607751 diff --git a/Luogu/P2698/data/P2698_8.out b/Luogu/P2698/data/P2698_8.out new file mode 100644 index 00000000..9a7c0910 --- /dev/null +++ b/Luogu/P2698/data/P2698_8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:454dd9bee3713349377d922ca2f240658238b83a8386948f9931f4808d253d89 +size 5 diff --git a/Luogu/P2698/data/P2698_9.in b/Luogu/P2698/data/P2698_9.in new file mode 100644 index 00000000..f6c9904c --- /dev/null +++ b/Luogu/P2698/data/P2698_9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c516518fd4f74beac03a827aea1d67ea29f52402bc3af11bbeed2c4eae9fe4b9 +size 969441 diff --git a/Luogu/P2698/data/P2698_9.out b/Luogu/P2698/data/P2698_9.out new file mode 100644 index 00000000..6688dc07 --- /dev/null +++ b/Luogu/P2698/data/P2698_9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1d258ee0abb363ec37f0ae6b24505f6a1c903729c6021860b733c1cf7a427e1d +size 6