From 546fa22701f6ed2c8009caea9314729b388c8494 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 15 Sep 2022 19:11:55 +0800 Subject: [PATCH] =?UTF-8?q?3781.=20=E5=B0=8FB=E7=9A=84=E8=AF=A2=E9=97=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://hydro.ac/d/bzoj/record/63230865bdf9bc31d160bed5 --- BZOJ/3781/3781.cpp | 72 +++++++++++++++++++++++++++++++++++++++++++ BZOJ/3781/data/1.in | 3 ++ BZOJ/3781/data/1.out | 3 ++ BZOJ/3781/data/10.in | 3 ++ BZOJ/3781/data/10.out | 3 ++ BZOJ/3781/data/2.in | 3 ++ BZOJ/3781/data/2.out | 3 ++ BZOJ/3781/data/3.in | 3 ++ BZOJ/3781/data/3.out | 3 ++ BZOJ/3781/data/4.in | 3 ++ BZOJ/3781/data/4.out | 3 ++ BZOJ/3781/data/5.in | 3 ++ BZOJ/3781/data/5.out | 3 ++ BZOJ/3781/data/6.in | 3 ++ BZOJ/3781/data/6.out | 3 ++ BZOJ/3781/data/7.in | 3 ++ BZOJ/3781/data/7.out | 3 ++ BZOJ/3781/data/8.in | 3 ++ BZOJ/3781/data/8.out | 3 ++ BZOJ/3781/data/9.in | 3 ++ BZOJ/3781/data/9.out | 3 ++ 21 files changed, 132 insertions(+) create mode 100644 BZOJ/3781/3781.cpp create mode 100644 BZOJ/3781/data/1.in create mode 100644 BZOJ/3781/data/1.out create mode 100644 BZOJ/3781/data/10.in create mode 100644 BZOJ/3781/data/10.out create mode 100644 BZOJ/3781/data/2.in create mode 100644 BZOJ/3781/data/2.out create mode 100644 BZOJ/3781/data/3.in create mode 100644 BZOJ/3781/data/3.out create mode 100644 BZOJ/3781/data/4.in create mode 100644 BZOJ/3781/data/4.out create mode 100644 BZOJ/3781/data/5.in create mode 100644 BZOJ/3781/data/5.out create mode 100644 BZOJ/3781/data/6.in create mode 100644 BZOJ/3781/data/6.out create mode 100644 BZOJ/3781/data/7.in create mode 100644 BZOJ/3781/data/7.out create mode 100644 BZOJ/3781/data/8.in create mode 100644 BZOJ/3781/data/8.out create mode 100644 BZOJ/3781/data/9.in create mode 100644 BZOJ/3781/data/9.out diff --git a/BZOJ/3781/3781.cpp b/BZOJ/3781/3781.cpp new file mode 100644 index 00000000..af64baec --- /dev/null +++ b/BZOJ/3781/3781.cpp @@ -0,0 +1,72 @@ +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 5e4 + 5; + +int n, m, k, a[N], c[N], t, ans[N]; +std::vector> q; + +inline void add(int x, int &res) { + res += 2 * c[x] + 1; + c[x]++; +} + +inline void del(int x, int &res) { + res -= 2 * c[x] - 1; + c[x]--; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> m >> k; + + for (int i = 1; i <= n; i++) { + cin >> a[i]; + } + + t = sqrt(n); + + for (int i = 1, l, r; i <= m; i++) { + cin >> l >> r; + + q.push_back(std::make_tuple(i, l, r)); + } + + std::sort(q.begin(), q.end(), [&](auto a, auto b) { + int p = std::get<1>(a) / t, + q = std::get<1>(b) / t; + + return p == q + ? (p & 1) + ? std::get<2>(a) < std::get<2>(b) + : std::get<2>(a) > std::get<2>(b) + : p < q; + }); + + int i = 0, j = 1, res = 0, id, l, r; + for (auto &e : q) { + std::tie(id, l, r) = e; + + while (i < r) add(a[++i], res); + while (i > r) del(a[i--], res); + while (j < l) del(a[j++], res); + while (j > l) add(a[--j], res); + + ans[id] = res; + } + + for (int i = 1; i <= m; i++) { + cout << ans[i] << endl; + } + + return 0; +} diff --git a/BZOJ/3781/data/1.in b/BZOJ/3781/data/1.in new file mode 100644 index 00000000..dfc40d1f --- /dev/null +++ b/BZOJ/3781/data/1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:54925f4de2aff1cb263f9e325fdbe0dfc44f1e52c6fc15e19aa89f74c65f4288 +size 851779 diff --git a/BZOJ/3781/data/1.out b/BZOJ/3781/data/1.out new file mode 100644 index 00000000..942361a7 --- /dev/null +++ b/BZOJ/3781/data/1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:41fa9ce4bb7e2ff2dc1b93e6f0332d412ac2d4675d8a22270b6aad677060e9cc +size 430301 diff --git a/BZOJ/3781/data/10.in b/BZOJ/3781/data/10.in new file mode 100644 index 00000000..d482a3e9 --- /dev/null +++ b/BZOJ/3781/data/10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:96f4f43664b452eaf78a0463afb6c580bd5ec3788d0966521426a146f5a4b7a5 +size 856715 diff --git a/BZOJ/3781/data/10.out b/BZOJ/3781/data/10.out new file mode 100644 index 00000000..21d3a6f8 --- /dev/null +++ b/BZOJ/3781/data/10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:048ed9507f93989dde09450b94216dafed2a755f935f37b1e26e91c9d91c8f46 +size 431050 diff --git a/BZOJ/3781/data/2.in b/BZOJ/3781/data/2.in new file mode 100644 index 00000000..9dca86b3 --- /dev/null +++ b/BZOJ/3781/data/2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9564e8b6506cc6aebcb17cb7bab60dc0be7635f7c46ea1c1756b4533f186ca7e +size 723898 diff --git a/BZOJ/3781/data/2.out b/BZOJ/3781/data/2.out new file mode 100644 index 00000000..108fcf57 --- /dev/null +++ b/BZOJ/3781/data/2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:061cffbe29482ceb33469df5ec1e6c10af112bfba2d66c56375d8662d758e955 +size 380087 diff --git a/BZOJ/3781/data/3.in b/BZOJ/3781/data/3.in new file mode 100644 index 00000000..e7823c39 --- /dev/null +++ b/BZOJ/3781/data/3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c80c40c3335f604629fc5f15509c8c31ba4b8d75d3beac73ae2c138a05cf00de +size 871352 diff --git a/BZOJ/3781/data/3.out b/BZOJ/3781/data/3.out new file mode 100644 index 00000000..a76a4ee0 --- /dev/null +++ b/BZOJ/3781/data/3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d4915d2e262642c89faf561bfcbda000b2ad00dbcf170d6868e7879717b325bf +size 430631 diff --git a/BZOJ/3781/data/4.in b/BZOJ/3781/data/4.in new file mode 100644 index 00000000..1ef615ce --- /dev/null +++ b/BZOJ/3781/data/4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a295a1de19980a280890a55e3865c27cbb270c6c47d595e68c4d5dfe2958b03e +size 872065 diff --git a/BZOJ/3781/data/4.out b/BZOJ/3781/data/4.out new file mode 100644 index 00000000..c60bbc98 --- /dev/null +++ b/BZOJ/3781/data/4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6334d568dabf75a1628c6d4ee1db02f50404eeef4f23be6b5e132cd0c2da55f8 +size 430650 diff --git a/BZOJ/3781/data/5.in b/BZOJ/3781/data/5.in new file mode 100644 index 00000000..355d69a7 --- /dev/null +++ b/BZOJ/3781/data/5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3a777b2bd7e63d70656d2fdc6616a6584a6c78126966ac457a57e346efcf3c64 +size 871790 diff --git a/BZOJ/3781/data/5.out b/BZOJ/3781/data/5.out new file mode 100644 index 00000000..468ee2e1 --- /dev/null +++ b/BZOJ/3781/data/5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bb199a622dd66fe44128f7d914f2b8f9f1ec1a8daed5c73a790e0ad6aa538f12 +size 430422 diff --git a/BZOJ/3781/data/6.in b/BZOJ/3781/data/6.in new file mode 100644 index 00000000..59a505da --- /dev/null +++ b/BZOJ/3781/data/6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:36c129a12a040d6090cdecf2de84233f12d7025e6fb32b581256ac85eb272e9e +size 871857 diff --git a/BZOJ/3781/data/6.out b/BZOJ/3781/data/6.out new file mode 100644 index 00000000..4f646594 --- /dev/null +++ b/BZOJ/3781/data/6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9738a61cea54e76f12f41d7cf0d7977bb195f0451b134fb1f7b5d5d164677c48 +size 430836 diff --git a/BZOJ/3781/data/7.in b/BZOJ/3781/data/7.in new file mode 100644 index 00000000..2477ed60 --- /dev/null +++ b/BZOJ/3781/data/7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0d18ad1e3e1b74df7a1f4a1e9761b5f1996966aeaa6a648d807c390270f6e004 +size 723618 diff --git a/BZOJ/3781/data/7.out b/BZOJ/3781/data/7.out new file mode 100644 index 00000000..ac94e602 --- /dev/null +++ b/BZOJ/3781/data/7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bec1bf0b6489fd596a4f7bcdeb9e7de464e7806682cb6ddfeaa505bdccfd2e92 +size 380421 diff --git a/BZOJ/3781/data/8.in b/BZOJ/3781/data/8.in new file mode 100644 index 00000000..647191d2 --- /dev/null +++ b/BZOJ/3781/data/8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:82a7317cf1ecf0dbc56b9359ca1fb523825bf4d77864bcfe160ab118db44388e +size 723746 diff --git a/BZOJ/3781/data/8.out b/BZOJ/3781/data/8.out new file mode 100644 index 00000000..20d25658 --- /dev/null +++ b/BZOJ/3781/data/8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4071ac0ae80b8035bade055f2b0dd1090886bc9acf861971149c83b0aa7ad548 +size 380142 diff --git a/BZOJ/3781/data/9.in b/BZOJ/3781/data/9.in new file mode 100644 index 00000000..b3b74b83 --- /dev/null +++ b/BZOJ/3781/data/9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cfdf5b886877691ad2e10c87dc4b06e397b078a652a1988159ccf0e4febf23e3 +size 849297 diff --git a/BZOJ/3781/data/9.out b/BZOJ/3781/data/9.out new file mode 100644 index 00000000..b7361d52 --- /dev/null +++ b/BZOJ/3781/data/9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:81e3272284f51f09e727149f1a291276f4984adfbe38effec2fb05b69117e07b +size 430036