From fefe23f287bb4b48fd85e82a82bfa3259715f383 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 15 Sep 2022 18:23:42 +0800 Subject: [PATCH] =?UTF-8?q?3236.=20[Ahoi2013]=20=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://hydro.ac/d/bzoj/record/6322f16dbdf9bc31d160a4f9 --- BZOJ/3236/3236.cpp | 88 +++++++++++++++++++++++++++++++++++++++++++ BZOJ/3236/data/1.in | 3 ++ BZOJ/3236/data/1.out | 3 ++ BZOJ/3236/data/10.in | 3 ++ BZOJ/3236/data/10.out | 3 ++ BZOJ/3236/data/11.in | 3 ++ BZOJ/3236/data/11.out | 3 ++ BZOJ/3236/data/12.in | 3 ++ BZOJ/3236/data/12.out | 3 ++ BZOJ/3236/data/13.in | 3 ++ BZOJ/3236/data/13.out | 3 ++ BZOJ/3236/data/14.in | 3 ++ BZOJ/3236/data/14.out | 3 ++ BZOJ/3236/data/15.in | 3 ++ BZOJ/3236/data/15.out | 3 ++ BZOJ/3236/data/16.in | 3 ++ BZOJ/3236/data/16.out | 3 ++ BZOJ/3236/data/17.in | 3 ++ BZOJ/3236/data/17.out | 3 ++ BZOJ/3236/data/18.in | 3 ++ BZOJ/3236/data/18.out | 3 ++ BZOJ/3236/data/19.in | 3 ++ BZOJ/3236/data/19.out | 3 ++ BZOJ/3236/data/2.in | 3 ++ BZOJ/3236/data/2.out | 3 ++ BZOJ/3236/data/20.in | 3 ++ BZOJ/3236/data/20.out | 3 ++ BZOJ/3236/data/3.in | 3 ++ BZOJ/3236/data/3.out | 3 ++ BZOJ/3236/data/4.in | 3 ++ BZOJ/3236/data/4.out | 3 ++ BZOJ/3236/data/5.in | 3 ++ BZOJ/3236/data/5.out | 3 ++ BZOJ/3236/data/6.in | 3 ++ BZOJ/3236/data/6.out | 3 ++ BZOJ/3236/data/7.in | 3 ++ BZOJ/3236/data/7.out | 3 ++ BZOJ/3236/data/8.in | 3 ++ BZOJ/3236/data/8.out | 3 ++ BZOJ/3236/data/9.in | 3 ++ BZOJ/3236/data/9.out | 3 ++ 41 files changed, 208 insertions(+) create mode 100644 BZOJ/3236/3236.cpp create mode 100644 BZOJ/3236/data/1.in create mode 100644 BZOJ/3236/data/1.out create mode 100644 BZOJ/3236/data/10.in create mode 100644 BZOJ/3236/data/10.out create mode 100644 BZOJ/3236/data/11.in create mode 100644 BZOJ/3236/data/11.out create mode 100644 BZOJ/3236/data/12.in create mode 100644 BZOJ/3236/data/12.out create mode 100644 BZOJ/3236/data/13.in create mode 100644 BZOJ/3236/data/13.out create mode 100644 BZOJ/3236/data/14.in create mode 100644 BZOJ/3236/data/14.out create mode 100644 BZOJ/3236/data/15.in create mode 100644 BZOJ/3236/data/15.out create mode 100644 BZOJ/3236/data/16.in create mode 100644 BZOJ/3236/data/16.out create mode 100644 BZOJ/3236/data/17.in create mode 100644 BZOJ/3236/data/17.out create mode 100644 BZOJ/3236/data/18.in create mode 100644 BZOJ/3236/data/18.out create mode 100644 BZOJ/3236/data/19.in create mode 100644 BZOJ/3236/data/19.out create mode 100644 BZOJ/3236/data/2.in create mode 100644 BZOJ/3236/data/2.out create mode 100644 BZOJ/3236/data/20.in create mode 100644 BZOJ/3236/data/20.out create mode 100644 BZOJ/3236/data/3.in create mode 100644 BZOJ/3236/data/3.out create mode 100644 BZOJ/3236/data/4.in create mode 100644 BZOJ/3236/data/4.out create mode 100644 BZOJ/3236/data/5.in create mode 100644 BZOJ/3236/data/5.out create mode 100644 BZOJ/3236/data/6.in create mode 100644 BZOJ/3236/data/6.out create mode 100644 BZOJ/3236/data/7.in create mode 100644 BZOJ/3236/data/7.out create mode 100644 BZOJ/3236/data/8.in create mode 100644 BZOJ/3236/data/8.out create mode 100644 BZOJ/3236/data/9.in create mode 100644 BZOJ/3236/data/9.out diff --git a/BZOJ/3236/3236.cpp b/BZOJ/3236/3236.cpp new file mode 100644 index 00000000..1e6b0b36 --- /dev/null +++ b/BZOJ/3236/3236.cpp @@ -0,0 +1,88 @@ +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e6 + 5; + +int n, m, w[N], c[N], c1[N], c2[N], t; +std::pair now, ans[N]; +std::vector> q; + +inline int lowbit(int x) { + return x & -x; +} + +void add(int *c, int x, int y) { + for (; x <= n; x += lowbit(x)) c[x] += y; +} + +int sum(int *c, int x) { + int res = 0; + for (; x; x -= lowbit(x)) res += c[x]; + return res; +} + +void add(int x) { + if (!c[x]++) add(c1, x, 1); + add(c2, x, 1); +} + +void del(int x) { + if (!--c[x]) add(c1, x, -1); + add(c2, x, -1); +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> m; + + for (int i = 1; i <= n; i++) { + cin >> w[i]; + } + + t = sqrt(n); + + for (int i = 1, l, r, a, b; i <= m; i++) { + cin >> l >> r >> a >> b; + + q.push_back(std::make_tuple(i, l, r, a, b)); + } + + std::sort(q.begin(), q.end(), [&](auto a, auto b) { + int p = std::get<1>(a) / t, + q = std::get<1>(b) / t; + int x = std::get<2>(a), + y = std::get<2>(b); + + return p == q + ? p & 1 ? x < y : x > y + : p < q; + }); + + int i = 0, j = 1; + for (auto &e : q) { + int id, l, r, a, b; + std::tie(id, l, r, a, b) = e; + + while (i < r) add(w[++i]); + while (i > r) del(w[i--]); + while (j < l) del(w[j++]); + while (j > l) add(w[--j]); + + ans[id] = std::make_pair(sum(c2, b) - sum(c2, a - 1), sum(c1, b) - sum(c1, a - 1)); + } + + for (int i = 1; i <= m; i++) { + cout << ans[i].first << ' ' << ans[i].second << endl; + } + + return 0; +} diff --git a/BZOJ/3236/data/1.in b/BZOJ/3236/data/1.in new file mode 100644 index 00000000..31871728 --- /dev/null +++ b/BZOJ/3236/data/1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:caf83c133850a95d3565de5dd4c3a871aca6da947886aae2f808d0bf558e7f28 +size 19496 diff --git a/BZOJ/3236/data/1.out b/BZOJ/3236/data/1.out new file mode 100644 index 00000000..7296ec17 --- /dev/null +++ b/BZOJ/3236/data/1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e506d1ec1819e4a5fe1e42bbdbd952d5c99551a9aa864ffb421fc849b92f4a14 +size 6471 diff --git a/BZOJ/3236/data/10.in b/BZOJ/3236/data/10.in new file mode 100644 index 00000000..9b001660 --- /dev/null +++ b/BZOJ/3236/data/10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9c07154f44bca5e8a67e1aee238c1d2ffec6ce90378da3c0ea00f77b14c6d65a +size 19450 diff --git a/BZOJ/3236/data/10.out b/BZOJ/3236/data/10.out new file mode 100644 index 00000000..4c52d161 --- /dev/null +++ b/BZOJ/3236/data/10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:07939a464973e0dbbfda8404f56a761b00f090aa0f122ad0a190d182f628251a +size 6424 diff --git a/BZOJ/3236/data/11.in b/BZOJ/3236/data/11.in new file mode 100644 index 00000000..6f4b017b --- /dev/null +++ b/BZOJ/3236/data/11.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1fcdba139a998872f02112de416aeab0b7dad131ef3ae0bc2f07d5f1bdfa37d0 +size 19419 diff --git a/BZOJ/3236/data/11.out b/BZOJ/3236/data/11.out new file mode 100644 index 00000000..f3dbf506 --- /dev/null +++ b/BZOJ/3236/data/11.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:57eca610e3d706533bb3a8bc68df3f08181d8c5d8b1dce7a200ede88c9b2d976 +size 6407 diff --git a/BZOJ/3236/data/12.in b/BZOJ/3236/data/12.in new file mode 100644 index 00000000..7bf426fb --- /dev/null +++ b/BZOJ/3236/data/12.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ea599d0cf974e42b7338361c86e02f8ec15b2f925a4c166c2228d4758b4ebc86 +size 2785527 diff --git a/BZOJ/3236/data/12.out b/BZOJ/3236/data/12.out new file mode 100644 index 00000000..f09ac698 --- /dev/null +++ b/BZOJ/3236/data/12.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6c2927193b7c5395d06fc89086e981d8865082380c309a265b16147ee36420eb +size 1048574 diff --git a/BZOJ/3236/data/13.in b/BZOJ/3236/data/13.in new file mode 100644 index 00000000..180a33b6 --- /dev/null +++ b/BZOJ/3236/data/13.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f2fa64ddb9a9e9610856746472cd08cb1caf54c3387ffc4dad19c096b3cc8bd9 +size 2944304 diff --git a/BZOJ/3236/data/13.out b/BZOJ/3236/data/13.out new file mode 100644 index 00000000..2ef5aee6 --- /dev/null +++ b/BZOJ/3236/data/13.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3b28313692f602966e366a0b6d705bce65e9aa162cabe4983f183aecbc0718a2 +size 1035087 diff --git a/BZOJ/3236/data/14.in b/BZOJ/3236/data/14.in new file mode 100644 index 00000000..34cc8916 --- /dev/null +++ b/BZOJ/3236/data/14.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:edf20bce06d86398233e699382f059b745330b591c426fc6ba20a84baf3a91d0 +size 2944418 diff --git a/BZOJ/3236/data/14.out b/BZOJ/3236/data/14.out new file mode 100644 index 00000000..a28caeac --- /dev/null +++ b/BZOJ/3236/data/14.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f03a1f57d2396991c68ef5e51a64b273cb558fc9fdc9154c2daa745a20253d96 +size 1035796 diff --git a/BZOJ/3236/data/15.in b/BZOJ/3236/data/15.in new file mode 100644 index 00000000..cd3d3008 --- /dev/null +++ b/BZOJ/3236/data/15.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3e12475fd0a3ccdc2d969d3463ebfca6cfa4a03f1607206ed8becb96957313c4 +size 2944534 diff --git a/BZOJ/3236/data/15.out b/BZOJ/3236/data/15.out new file mode 100644 index 00000000..96b0e328 --- /dev/null +++ b/BZOJ/3236/data/15.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8808dd20bbe40bb381fbd11085b4d55be97ca23aa2bc4a49b3cc5e999daff98a +size 1034864 diff --git a/BZOJ/3236/data/16.in b/BZOJ/3236/data/16.in new file mode 100644 index 00000000..dbe1b830 --- /dev/null +++ b/BZOJ/3236/data/16.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b38b8310dcdd421f699cb47333906548e1a642cf252fc9c0c445fcb29b6cf92a +size 19481 diff --git a/BZOJ/3236/data/16.out b/BZOJ/3236/data/16.out new file mode 100644 index 00000000..2aad9d37 --- /dev/null +++ b/BZOJ/3236/data/16.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1e5d218e0b80df06e61f246872f2b5a19dcda13aabc76c57018d1bf9d88307f6 +size 6370 diff --git a/BZOJ/3236/data/17.in b/BZOJ/3236/data/17.in new file mode 100644 index 00000000..51b08274 --- /dev/null +++ b/BZOJ/3236/data/17.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e00701ebf79494a65d29a82177689c54f4b16b1188e9e2286db169943ac4ea39 +size 2785059 diff --git a/BZOJ/3236/data/17.out b/BZOJ/3236/data/17.out new file mode 100644 index 00000000..bd54dcb5 --- /dev/null +++ b/BZOJ/3236/data/17.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a9a366a870e4e4edc1a79403d036955ed7c94c473daccbbdc28f67e0b2e11d4b +size 1048914 diff --git a/BZOJ/3236/data/18.in b/BZOJ/3236/data/18.in new file mode 100644 index 00000000..e882b595 --- /dev/null +++ b/BZOJ/3236/data/18.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:46a777cb57cb0f4142d224d3ed3046476a8a2e90169e4c460893ae735b229ec3 +size 24145557 diff --git a/BZOJ/3236/data/18.out b/BZOJ/3236/data/18.out new file mode 100644 index 00000000..864903ce --- /dev/null +++ b/BZOJ/3236/data/18.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9fe13ef6c312f790a091a15cb771514fb89ddd16aef8442e818b9c2e19b8ce3c +size 10355408 diff --git a/BZOJ/3236/data/19.in b/BZOJ/3236/data/19.in new file mode 100644 index 00000000..1a6e6fcb --- /dev/null +++ b/BZOJ/3236/data/19.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ac5bbb9cee84fa0ec1aa36f8bb7823017a7537cc12e75470fead05bf49bec665 +size 19442 diff --git a/BZOJ/3236/data/19.out b/BZOJ/3236/data/19.out new file mode 100644 index 00000000..c40602dd --- /dev/null +++ b/BZOJ/3236/data/19.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d1722bb87fed440f2c0a7482d037461d12b4835b9b80c077fecab87a8e4512d9 +size 6462 diff --git a/BZOJ/3236/data/2.in b/BZOJ/3236/data/2.in new file mode 100644 index 00000000..324a7a71 --- /dev/null +++ b/BZOJ/3236/data/2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:203bdc079c7e9144569c7956b6b515f168ef33abb60b1634f16c8db90d746f72 +size 2944228 diff --git a/BZOJ/3236/data/2.out b/BZOJ/3236/data/2.out new file mode 100644 index 00000000..2128028e --- /dev/null +++ b/BZOJ/3236/data/2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:921275771b82d6c895ac813ccf9beaf4ed1f0f2d3352d8684b3361c15fc56b11 +size 1034947 diff --git a/BZOJ/3236/data/20.in b/BZOJ/3236/data/20.in new file mode 100644 index 00000000..0c45aff8 --- /dev/null +++ b/BZOJ/3236/data/20.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c9dbbbe930325793afa5290828564627c5f99de92d5e9f0c97b2600c53730677 +size 19508966 diff --git a/BZOJ/3236/data/20.out b/BZOJ/3236/data/20.out new file mode 100644 index 00000000..89a400ef --- /dev/null +++ b/BZOJ/3236/data/20.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3dbbffc32162309bbadcba681dc030544cf7149977f45864e158897bd019480a +size 8370957 diff --git a/BZOJ/3236/data/3.in b/BZOJ/3236/data/3.in new file mode 100644 index 00000000..a2d566be --- /dev/null +++ b/BZOJ/3236/data/3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8b936c0965094c322312dc4241bfe604ca5f61510b9383b147bac974eddfc3a9 +size 2784527 diff --git a/BZOJ/3236/data/3.out b/BZOJ/3236/data/3.out new file mode 100644 index 00000000..6ecde787 --- /dev/null +++ b/BZOJ/3236/data/3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8798eb28c4757790539bef652a36bc9a1b68a9a3811670ddb766035235325b41 +size 1048488 diff --git a/BZOJ/3236/data/4.in b/BZOJ/3236/data/4.in new file mode 100644 index 00000000..6c0f3d8e --- /dev/null +++ b/BZOJ/3236/data/4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3ec07d9b90842d9093ae7bf5abe6e6534d2d6a3abda1344320d2910e08a5cc2a +size 2785032 diff --git a/BZOJ/3236/data/4.out b/BZOJ/3236/data/4.out new file mode 100644 index 00000000..93d4b45c --- /dev/null +++ b/BZOJ/3236/data/4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a2392bf194ac5580b4b384fe5ee02b7cb020da0b88ee073c4c8ef072dbe2ca0a +size 1048795 diff --git a/BZOJ/3236/data/5.in b/BZOJ/3236/data/5.in new file mode 100644 index 00000000..09c57f9f --- /dev/null +++ b/BZOJ/3236/data/5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8f088a8a1c32e1070792aac2300f9eeea42496dc68b0904a736e0198f45f9d72 +size 2944738 diff --git a/BZOJ/3236/data/5.out b/BZOJ/3236/data/5.out new file mode 100644 index 00000000..da73a81b --- /dev/null +++ b/BZOJ/3236/data/5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:af307fb857cdc7338509de0404445e907dc2b2012f6444cd2e530f635db0b65a +size 1035675 diff --git a/BZOJ/3236/data/6.in b/BZOJ/3236/data/6.in new file mode 100644 index 00000000..a0b436cf --- /dev/null +++ b/BZOJ/3236/data/6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f81a8e8661d0a3d76b082ccff3754926925082c67604140d09d7d6c872e76d51 +size 19508824 diff --git a/BZOJ/3236/data/6.out b/BZOJ/3236/data/6.out new file mode 100644 index 00000000..bae18f02 --- /dev/null +++ b/BZOJ/3236/data/6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d45e5e79604b0c5dd359f863611925bc072c03c6094f4dde6a22a56e4a965ea3 +size 8365702 diff --git a/BZOJ/3236/data/7.in b/BZOJ/3236/data/7.in new file mode 100644 index 00000000..43829855 --- /dev/null +++ b/BZOJ/3236/data/7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a485360577975b3202debbb547a4ba40b6bdfdb5ed7f66c62e2c23f76d91ca85 +size 2784851 diff --git a/BZOJ/3236/data/7.out b/BZOJ/3236/data/7.out new file mode 100644 index 00000000..8f0ddc87 --- /dev/null +++ b/BZOJ/3236/data/7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f387361bbd49120e8e4d3b4e6038951767c92cfa4b356d2b945216000de132d9 +size 1049427 diff --git a/BZOJ/3236/data/8.in b/BZOJ/3236/data/8.in new file mode 100644 index 00000000..c3ae94d2 --- /dev/null +++ b/BZOJ/3236/data/8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9baf6734789a47ca32b193ae025c3c81ea7907154ce40a56537f0338998ad9ca +size 24145192 diff --git a/BZOJ/3236/data/8.out b/BZOJ/3236/data/8.out new file mode 100644 index 00000000..c6da1c4d --- /dev/null +++ b/BZOJ/3236/data/8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:372d778b0f120a106c32c94fac663bb7c846dbc0d03fc84b269755da59d7450c +size 10359770 diff --git a/BZOJ/3236/data/9.in b/BZOJ/3236/data/9.in new file mode 100644 index 00000000..c3e073fa --- /dev/null +++ b/BZOJ/3236/data/9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:27fe6d460b99b8682dbdabe9419176b298eb7ed30ba7d9f486d107d529d664a1 +size 19473 diff --git a/BZOJ/3236/data/9.out b/BZOJ/3236/data/9.out new file mode 100644 index 00000000..a9bb6995 --- /dev/null +++ b/BZOJ/3236/data/9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:11623bcaaa46e3b8637f1218d7c4810362bce8510718c9d3750dccae099fcfc7 +size 6403