From 226513485c8302a63f0bc2635960a837d02e0154 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 15 Sep 2022 11:39:16 +0800 Subject: [PATCH] P4269 [USACO18FEB]Snow Boots G https://www.luogu.com.cn/record/86653460 --- Luogu/P4269/P4269.cpp | 86 +++++++++++++++++++++++++++++++++++ Luogu/P4269/data/P4269_1.in | 3 ++ Luogu/P4269/data/P4269_1.out | 3 ++ Luogu/P4269/data/P4269_10.in | 3 ++ Luogu/P4269/data/P4269_10.out | 3 ++ Luogu/P4269/data/P4269_11.in | 3 ++ Luogu/P4269/data/P4269_11.out | 3 ++ Luogu/P4269/data/P4269_12.in | 3 ++ Luogu/P4269/data/P4269_12.out | 3 ++ Luogu/P4269/data/P4269_2.in | 3 ++ Luogu/P4269/data/P4269_2.out | 3 ++ Luogu/P4269/data/P4269_3.in | 3 ++ Luogu/P4269/data/P4269_3.out | 3 ++ Luogu/P4269/data/P4269_4.in | 3 ++ Luogu/P4269/data/P4269_4.out | 3 ++ Luogu/P4269/data/P4269_5.in | 3 ++ Luogu/P4269/data/P4269_5.out | 3 ++ Luogu/P4269/data/P4269_6.in | 3 ++ Luogu/P4269/data/P4269_6.out | 3 ++ Luogu/P4269/data/P4269_7.in | 3 ++ Luogu/P4269/data/P4269_7.out | 3 ++ Luogu/P4269/data/P4269_8.in | 3 ++ Luogu/P4269/data/P4269_8.out | 3 ++ Luogu/P4269/data/P4269_9.in | 3 ++ Luogu/P4269/data/P4269_9.out | 3 ++ 25 files changed, 158 insertions(+) create mode 100644 Luogu/P4269/P4269.cpp create mode 100644 Luogu/P4269/data/P4269_1.in create mode 100644 Luogu/P4269/data/P4269_1.out create mode 100644 Luogu/P4269/data/P4269_10.in create mode 100644 Luogu/P4269/data/P4269_10.out create mode 100644 Luogu/P4269/data/P4269_11.in create mode 100644 Luogu/P4269/data/P4269_11.out create mode 100644 Luogu/P4269/data/P4269_12.in create mode 100644 Luogu/P4269/data/P4269_12.out create mode 100644 Luogu/P4269/data/P4269_2.in create mode 100644 Luogu/P4269/data/P4269_2.out create mode 100644 Luogu/P4269/data/P4269_3.in create mode 100644 Luogu/P4269/data/P4269_3.out create mode 100644 Luogu/P4269/data/P4269_4.in create mode 100644 Luogu/P4269/data/P4269_4.out create mode 100644 Luogu/P4269/data/P4269_5.in create mode 100644 Luogu/P4269/data/P4269_5.out create mode 100644 Luogu/P4269/data/P4269_6.in create mode 100644 Luogu/P4269/data/P4269_6.out create mode 100644 Luogu/P4269/data/P4269_7.in create mode 100644 Luogu/P4269/data/P4269_7.out create mode 100644 Luogu/P4269/data/P4269_8.in create mode 100644 Luogu/P4269/data/P4269_8.out create mode 100644 Luogu/P4269/data/P4269_9.in create mode 100644 Luogu/P4269/data/P4269_9.out diff --git a/Luogu/P4269/P4269.cpp b/Luogu/P4269/P4269.cpp new file mode 100644 index 00000000..84814e58 --- /dev/null +++ b/Luogu/P4269/P4269.cpp @@ -0,0 +1,86 @@ +#include +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +int n, b; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> b; + + std::vector a(n), d(n); + + for (int &x : a) cin >> x; + + std::vector> shoes; + + for (int i = 0, s; i < b; i++) { + cin >> s >> d[i]; + + shoes.emplace_back(i, s); + } + + std::vector ans(n); + + auto solve = [&](int ql, int qr, int l, int r, auto &&solve) -> void { + if (ql > qr || l > r) return; + + if (l == r) { + for (int i = ql; i <= qr; i++) { + ans[shoes[i].first] = l; + } + + return; + } + + int mid = l + r >> 1; + std::deque q{0}; + std::vector f(n); + + for (int i = 1; i < n; i++) { + while (!q.empty() && i - q.front() > mid) q.pop_front(); + f[i] = std::max(a[i], f[q.front()]); + while (!q.empty() && f[i] <= f[q.back()]) q.pop_back(); + q.push_back(i); + } + + if (shoes[ql].second < *f.rbegin()) { + solve(ql, qr, mid + 1, r, solve); + } else if (shoes[qr].second >= *f.rbegin()) { + solve(ql, qr, l, mid, solve); + } else { + int pos = std::lower_bound( + shoes.begin() + ql, + shoes.begin() + qr + 1, + std::make_pair(0, *f.rbegin()), + [](auto &&lhs, auto &&rhs) -> bool { + return lhs.second >= rhs.second; + }) + - shoes.begin(); + + solve(ql, pos - 1, l, mid, solve); + solve(pos, qr, mid + 1, r, solve); + } + }; + + std::sort(shoes.begin(), shoes.end(), [](auto &&lhs, auto &&rhs) -> bool { + return lhs.second > rhs.second; + }); + + solve(0, b - 1, 1, n, solve); + + for (int i = 0; i < b; i++) { + cout << (ans[i] <= d[i]) << endl; + } + + return 0; +} diff --git a/Luogu/P4269/data/P4269_1.in b/Luogu/P4269/data/P4269_1.in new file mode 100644 index 00000000..5654ea4f --- /dev/null +++ b/Luogu/P4269/data/P4269_1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d58224733382946f0ce806338b7f81f09165486b42db03d529d2aff963dd92a3 +size 51 diff --git a/Luogu/P4269/data/P4269_1.out b/Luogu/P4269/data/P4269_1.out new file mode 100644 index 00000000..a838c213 --- /dev/null +++ b/Luogu/P4269/data/P4269_1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:69b2fb9d2264a11b5e5305e4a76f113b9bdab0d80e04ff47ee54e14069617e71 +size 14 diff --git a/Luogu/P4269/data/P4269_10.in b/Luogu/P4269/data/P4269_10.in new file mode 100644 index 00000000..827bf399 --- /dev/null +++ b/Luogu/P4269/data/P4269_10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c39b61b6744b590a0e16fcc1d3fed3ade48ca411559e40b53e9b48025cc17342 +size 2207967 diff --git a/Luogu/P4269/data/P4269_10.out b/Luogu/P4269/data/P4269_10.out new file mode 100644 index 00000000..0d3194f7 --- /dev/null +++ b/Luogu/P4269/data/P4269_10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:88d7b005a9052cc49c4726a29122eb8739e1e978747248b32b7a14222017db06 +size 196008 diff --git a/Luogu/P4269/data/P4269_11.in b/Luogu/P4269/data/P4269_11.in new file mode 100644 index 00000000..ff3e4143 --- /dev/null +++ b/Luogu/P4269/data/P4269_11.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:95606769eb7401fcf9a995268f99ec8ff290fda43eeebf6a609d4f9e75c8e33f +size 2211755 diff --git a/Luogu/P4269/data/P4269_11.out b/Luogu/P4269/data/P4269_11.out new file mode 100644 index 00000000..ce9b2649 --- /dev/null +++ b/Luogu/P4269/data/P4269_11.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6da27f447ecec974ff36e270ab498d066e2a16812e401d238f3f96b5d2ed0f7b +size 196008 diff --git a/Luogu/P4269/data/P4269_12.in b/Luogu/P4269/data/P4269_12.in new file mode 100644 index 00000000..b52758eb --- /dev/null +++ b/Luogu/P4269/data/P4269_12.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9db30410f90664667b93ad2bb74d67b33048c98c4d23968c96d374c75cfa0be4 +size 2218274 diff --git a/Luogu/P4269/data/P4269_12.out b/Luogu/P4269/data/P4269_12.out new file mode 100644 index 00000000..52df50bd --- /dev/null +++ b/Luogu/P4269/data/P4269_12.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:86248d4049213081f4a2e29fdb3c973c2c222d9af8681ba84a64358d667111ab +size 196008 diff --git a/Luogu/P4269/data/P4269_2.in b/Luogu/P4269/data/P4269_2.in new file mode 100644 index 00000000..72b05f88 --- /dev/null +++ b/Luogu/P4269/data/P4269_2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:395122da761bcce04f69b5202bbddedf3ff56c5db38136c8968f89b2c34a6a97 +size 21405 diff --git a/Luogu/P4269/data/P4269_2.out b/Luogu/P4269/data/P4269_2.out new file mode 100644 index 00000000..6aece45f --- /dev/null +++ b/Luogu/P4269/data/P4269_2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f56cadc59b49330deea8b618d2aeff7acdedc45bdfd74aff624e8ca8a63de862 +size 1968 diff --git a/Luogu/P4269/data/P4269_3.in b/Luogu/P4269/data/P4269_3.in new file mode 100644 index 00000000..4b3282ed --- /dev/null +++ b/Luogu/P4269/data/P4269_3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:94bc9098a948620074f6ac4f41e5162e0a39c82c75460616e4521a82e44e83ba +size 21540 diff --git a/Luogu/P4269/data/P4269_3.out b/Luogu/P4269/data/P4269_3.out new file mode 100644 index 00000000..0f2addca --- /dev/null +++ b/Luogu/P4269/data/P4269_3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d01febd7147024a080f5f1a021f175383b41f882c0e9aa35b3918d2d6ae52ee4 +size 1968 diff --git a/Luogu/P4269/data/P4269_4.in b/Luogu/P4269/data/P4269_4.in new file mode 100644 index 00000000..1ac7672b --- /dev/null +++ b/Luogu/P4269/data/P4269_4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:da3ff922f48b1587b73ab5b1b50b20c6ec6210f1f18d520f89a83fec8890c155 +size 21548 diff --git a/Luogu/P4269/data/P4269_4.out b/Luogu/P4269/data/P4269_4.out new file mode 100644 index 00000000..573af086 --- /dev/null +++ b/Luogu/P4269/data/P4269_4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d4e1cad9cfb0274ccd6d217e8e763f23f14ce046ba51480dc4e52f3eaba89897 +size 1968 diff --git a/Luogu/P4269/data/P4269_5.in b/Luogu/P4269/data/P4269_5.in new file mode 100644 index 00000000..9ce227b2 --- /dev/null +++ b/Luogu/P4269/data/P4269_5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7a48073994a5a72b552d37630200cdcbe756b87baa597c8096f5ee268ff63305 +size 1200234 diff --git a/Luogu/P4269/data/P4269_5.out b/Luogu/P4269/data/P4269_5.out new file mode 100644 index 00000000..42a5a10f --- /dev/null +++ b/Luogu/P4269/data/P4269_5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1a7ea4bfa55bd0a466bbd2f6dec41725f54fe2dd1f3fa90a546037702e88a029 +size 145586 diff --git a/Luogu/P4269/data/P4269_6.in b/Luogu/P4269/data/P4269_6.in new file mode 100644 index 00000000..a59657e7 --- /dev/null +++ b/Luogu/P4269/data/P4269_6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c58a72c6bc25243b7060ad8f169af5f4195ee03ce3c85f3ccd56ef59d487f634 +size 1204968 diff --git a/Luogu/P4269/data/P4269_6.out b/Luogu/P4269/data/P4269_6.out new file mode 100644 index 00000000..be35f2c3 --- /dev/null +++ b/Luogu/P4269/data/P4269_6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8576fe6a2fb9aafd4418ad042093a42c92eeea7e221c568113c4261d094e2c65 +size 145802 diff --git a/Luogu/P4269/data/P4269_7.in b/Luogu/P4269/data/P4269_7.in new file mode 100644 index 00000000..e26df833 --- /dev/null +++ b/Luogu/P4269/data/P4269_7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7204858cc1e0b6a82419ea063e065558dd0fda836fe6280935caa39adfa7377b +size 1211373 diff --git a/Luogu/P4269/data/P4269_7.out b/Luogu/P4269/data/P4269_7.out new file mode 100644 index 00000000..3fcf9c61 --- /dev/null +++ b/Luogu/P4269/data/P4269_7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:030335de8308bf2dae0a1201470306e998191e2f55b2e58a835db8d72a73726c +size 148648 diff --git a/Luogu/P4269/data/P4269_8.in b/Luogu/P4269/data/P4269_8.in new file mode 100644 index 00000000..1867d1f7 --- /dev/null +++ b/Luogu/P4269/data/P4269_8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:29dfa54f2700275590827d688d5179e88858b24b70f0918f362557cda0033aab +size 2059131 diff --git a/Luogu/P4269/data/P4269_8.out b/Luogu/P4269/data/P4269_8.out new file mode 100644 index 00000000..f08763f0 --- /dev/null +++ b/Luogu/P4269/data/P4269_8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ad3f2b6042e2a11d44d52efb35bce75293c519840825af09e5cbfc8bf6f1e152 +size 190160 diff --git a/Luogu/P4269/data/P4269_9.in b/Luogu/P4269/data/P4269_9.in new file mode 100644 index 00000000..44193091 --- /dev/null +++ b/Luogu/P4269/data/P4269_9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bdcc2953ba3dc08f85b257b1bc5ee3e5059e827373cbb3c7715aa832b7af7710 +size 2192026 diff --git a/Luogu/P4269/data/P4269_9.out b/Luogu/P4269/data/P4269_9.out new file mode 100644 index 00000000..e963c5ba --- /dev/null +++ b/Luogu/P4269/data/P4269_9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:266cc0b79724ff77a30b1c9602bfd79fe9c0394a03c8ee327d99e10d5b4ff6e1 +size 196008