From a30aba29ccab1710a3490badadf5eb9b67925092 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 9 Jun 2022 20:18:52 +0800 Subject: [PATCH] =?UTF-8?q?#112.=20=E4=B8=89=E7=BB=B4=E5=81=8F=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://loj.ac/s/1479241 --- LibreOJ/112/112.cpp | 113 +++++++++++++++++++++++++++++++++++ LibreOJ/112/data/flower0.in | 3 + LibreOJ/112/data/flower0.out | 3 + LibreOJ/112/data/flower1.in | 3 + LibreOJ/112/data/flower1.out | 3 + LibreOJ/112/data/flower2.in | 3 + LibreOJ/112/data/flower2.out | 3 + LibreOJ/112/data/flower3.in | 3 + LibreOJ/112/data/flower3.out | 3 + LibreOJ/112/data/flower4.in | 3 + LibreOJ/112/data/flower4.out | 3 + LibreOJ/112/data/flower5.in | 3 + LibreOJ/112/data/flower5.out | 3 + LibreOJ/112/data/flower6.in | 3 + LibreOJ/112/data/flower6.out | 3 + LibreOJ/112/data/flower7.in | 3 + LibreOJ/112/data/flower7.out | 3 + LibreOJ/112/data/flower8.in | 3 + LibreOJ/112/data/flower8.out | 3 + LibreOJ/112/data/flower9.in | 3 + LibreOJ/112/data/flower9.out | 3 + 21 files changed, 173 insertions(+) create mode 100644 LibreOJ/112/112.cpp create mode 100644 LibreOJ/112/data/flower0.in create mode 100644 LibreOJ/112/data/flower0.out create mode 100644 LibreOJ/112/data/flower1.in create mode 100644 LibreOJ/112/data/flower1.out create mode 100644 LibreOJ/112/data/flower2.in create mode 100644 LibreOJ/112/data/flower2.out create mode 100644 LibreOJ/112/data/flower3.in create mode 100644 LibreOJ/112/data/flower3.out create mode 100644 LibreOJ/112/data/flower4.in create mode 100644 LibreOJ/112/data/flower4.out create mode 100644 LibreOJ/112/data/flower5.in create mode 100644 LibreOJ/112/data/flower5.out create mode 100644 LibreOJ/112/data/flower6.in create mode 100644 LibreOJ/112/data/flower6.out create mode 100644 LibreOJ/112/data/flower7.in create mode 100644 LibreOJ/112/data/flower7.out create mode 100644 LibreOJ/112/data/flower8.in create mode 100644 LibreOJ/112/data/flower8.out create mode 100644 LibreOJ/112/data/flower9.in create mode 100644 LibreOJ/112/data/flower9.out diff --git a/LibreOJ/112/112.cpp b/LibreOJ/112/112.cpp new file mode 100644 index 00000000..eafba087 --- /dev/null +++ b/LibreOJ/112/112.cpp @@ -0,0 +1,113 @@ +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e5 + 5, + K = 2e5 + 5; + +int n, k, ans[K]; +int c[K]; + +struct node { + int a, b, c, cnt, res; + + node() + : a(0), b(0), c(0), cnt(0), res(0) {} + + node(int _a, int _b, int _c) + : a(_a), b(_b), c(_c), cnt(1), res(0) {} + + bool operator<(const node& x) const { + return a == x.a ? b == x.b ? c < x.c : b < x.b : a < x.a; + } + + bool operator==(const node& x) const { + return a == x.a && b == x.b && c == x.c; + } +} q[N], w[N]; + +inline int lowbit(int x) { + return x & -x; +} + +void add(int x, int y) { + for (; x <= 2e5; x += lowbit(x)) c[x] += y; +} + +int sum(int x) { + int res = 0; + for (; x; x -= lowbit(x)) res += c[x]; + return res; +} + +void merge_sort(int l, int r) { + if (l >= r) return; + + int mid = l + r >> 1; + + merge_sort(l, mid); + merge_sort(mid + 1, r); + + int i = l, j = mid + 1, k = 0; + + while (i <= mid && j <= r) { + if (q[i].b <= q[j].b) { + add(q[i].c, q[i].cnt); + w[++k] = q[i++]; + } else { + q[j].res += sum(q[j].c); + w[++k] = q[j++]; + } + } + + while (i <= mid) { + add(q[i].c, q[i].cnt); + w[++k] = q[i++]; + } + + while (j <= r) { + q[j].res += sum(q[j].c); + w[++k] = q[j++]; + } + + for (int i = l; i <= mid; i++) add(q[i].c, -q[i].cnt); + for (int i = l, j = 1; j <= k; i++, j++) q[i] = w[j]; +} + +int main() { + std::ios::sync_with_stdio(false); + + cin >> n >> k; + + for (int i = 1, a, b, c; i <= n; i++) { + cin >> a >> b >> c; + + q[i] = node(a, b, c); + } + + std::sort(q + 1, q + 1 + n); + + int k = 1; + for (int i = 2; i <= n; i++) { + if (q[i] == q[k]) { + q[k].cnt++; + } else { + q[++k] = q[i]; + } + } + + merge_sort(1, k); + + for (int i = 1; i <= k; i++) { + ans[q[i].res + q[i].cnt - 1] += q[i].cnt; + } + + for (int i = 0; i < n; i++) { + cout << ans[i] << endl; + } + + return 0; +} diff --git a/LibreOJ/112/data/flower0.in b/LibreOJ/112/data/flower0.in new file mode 100644 index 00000000..50a9f681 --- /dev/null +++ b/LibreOJ/112/data/flower0.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:960c198c3c396ed753ce2a16a1e515722c580fc24e61c29046eda7a9651f416a +size 76 diff --git a/LibreOJ/112/data/flower0.out b/LibreOJ/112/data/flower0.out new file mode 100644 index 00000000..b4f4c247 --- /dev/null +++ b/LibreOJ/112/data/flower0.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e03aad1f786c12996e17c035a0d2eb695f62be8262cef5152de1d78b6d120b03 +size 30 diff --git a/LibreOJ/112/data/flower1.in b/LibreOJ/112/data/flower1.in new file mode 100644 index 00000000..eaba7219 --- /dev/null +++ b/LibreOJ/112/data/flower1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7742cccc8d510d76b67e8be0d63e545f300d37fd85deb382e09290d87ab9c4fd +size 12706 diff --git a/LibreOJ/112/data/flower1.out b/LibreOJ/112/data/flower1.out new file mode 100644 index 00000000..dd9b6c16 --- /dev/null +++ b/LibreOJ/112/data/flower1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2280c18dfef0a2bf32cd938c4a85bb89950cbd32858f134cf73506f0c5f36460 +size 3018 diff --git a/LibreOJ/112/data/flower2.in b/LibreOJ/112/data/flower2.in new file mode 100644 index 00000000..9dfe0bc3 --- /dev/null +++ b/LibreOJ/112/data/flower2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:209b74da2a340f0499875a9c2a390abbe2b090b714ab3dd6dc0536625113aa60 +size 126766 diff --git a/LibreOJ/112/data/flower2.out b/LibreOJ/112/data/flower2.out new file mode 100644 index 00000000..5cc69fd8 --- /dev/null +++ b/LibreOJ/112/data/flower2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a578a0c8514fb406aa31d2c227b946ba84e6a126a874c5b1485b1cab0a072304 +size 30213 diff --git a/LibreOJ/112/data/flower3.in b/LibreOJ/112/data/flower3.in new file mode 100644 index 00000000..cc04f665 --- /dev/null +++ b/LibreOJ/112/data/flower3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c109dbdd9a6b29a67ea679b669001b3e0b2cb98313aaa697f8815eecd1cf3adb +size 470109 diff --git a/LibreOJ/112/data/flower3.out b/LibreOJ/112/data/flower3.out new file mode 100644 index 00000000..abec3f8e --- /dev/null +++ b/LibreOJ/112/data/flower3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fab6388f641fc57e069d15b2181b28fc25d52ca7da1902170c46123473386f50 +size 90630 diff --git a/LibreOJ/112/data/flower4.in b/LibreOJ/112/data/flower4.in new file mode 100644 index 00000000..06716dcf --- /dev/null +++ b/LibreOJ/112/data/flower4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:58e798b92af9088c36740f2259d1d8814a3de9671398c350e2194ef53285dcb1 +size 940829 diff --git a/LibreOJ/112/data/flower4.out b/LibreOJ/112/data/flower4.out new file mode 100644 index 00000000..a38516af --- /dev/null +++ b/LibreOJ/112/data/flower4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f1a75fd3a622534aec6318bc28ee0f34018e89bef86a3b2eb57df360edcc7662 +size 181213 diff --git a/LibreOJ/112/data/flower5.in b/LibreOJ/112/data/flower5.in new file mode 100644 index 00000000..9994b935 --- /dev/null +++ b/LibreOJ/112/data/flower5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:69e84e5037a9d4daada391cce4396f19e705431c381031de2d563fc56bd4a421 +size 1566452 diff --git a/LibreOJ/112/data/flower5.out b/LibreOJ/112/data/flower5.out new file mode 100644 index 00000000..3e797992 --- /dev/null +++ b/LibreOJ/112/data/flower5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:43f1416ae7487a940c04fc9a7e7d06c71d5bedb68cc7aaa887452d8a185e0004 +size 302023 diff --git a/LibreOJ/112/data/flower6.in b/LibreOJ/112/data/flower6.in new file mode 100644 index 00000000..f9500656 --- /dev/null +++ b/LibreOJ/112/data/flower6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:422c5413c6b91d8e47b6e55246926424541c72ce25fa2505213f9d11b4173c0d +size 507986 diff --git a/LibreOJ/112/data/flower6.out b/LibreOJ/112/data/flower6.out new file mode 100644 index 00000000..fa28a746 --- /dev/null +++ b/LibreOJ/112/data/flower6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:222e3cf1721dd03796ba6263402aab9f3ef70fd77cdc27f0ac7f1c33ea30a373 +size 75490 diff --git a/LibreOJ/112/data/flower7.in b/LibreOJ/112/data/flower7.in new file mode 100644 index 00000000..535a4869 --- /dev/null +++ b/LibreOJ/112/data/flower7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bd6612d541e359e1cb66d9af2838c38e39d265409c3dfc6b313fef45b1a8433a +size 1137282 diff --git a/LibreOJ/112/data/flower7.out b/LibreOJ/112/data/flower7.out new file mode 100644 index 00000000..529b41af --- /dev/null +++ b/LibreOJ/112/data/flower7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5749ea101bc3f57d6bde54c5a23226a5c9f74e61fb89a466ef9eb91b00be03ae +size 302040 diff --git a/LibreOJ/112/data/flower8.in b/LibreOJ/112/data/flower8.in new file mode 100644 index 00000000..cfe7fb30 --- /dev/null +++ b/LibreOJ/112/data/flower8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:92000696d84bdc04bd91d75904f56c7e7d04537890fb1e554aed549dcf032299 +size 1733097 diff --git a/LibreOJ/112/data/flower8.out b/LibreOJ/112/data/flower8.out new file mode 100644 index 00000000..19d931d1 --- /dev/null +++ b/LibreOJ/112/data/flower8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d1b3d02b2bfc6d232e0b2ae3dc6d1cfed7e76a3f9a2946cbb51e4fa9fdd527e5 +size 302050 diff --git a/LibreOJ/112/data/flower9.in b/LibreOJ/112/data/flower9.in new file mode 100644 index 00000000..41c50ffb --- /dev/null +++ b/LibreOJ/112/data/flower9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f682dcadff6af27e00cea354ab37026954af477b670fe406e63860a499845502 +size 2034482 diff --git a/LibreOJ/112/data/flower9.out b/LibreOJ/112/data/flower9.out new file mode 100644 index 00000000..d7b494f7 --- /dev/null +++ b/LibreOJ/112/data/flower9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e1bdec83676e09a92ae65b4ba087e027e5045aa497c14e09019b95d6e7d69f7e +size 301974