From c792347fc7bdd923176586eed9b67ef5d4ab005c Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 2 Jun 2022 09:10:36 +0800 Subject: [PATCH] =?UTF-8?q?P3901=20=E6=95=B0=E5=88=97=E6=89=BE=E4=B8=8D?= =?UTF-8?q?=E5=90=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/76778782 --- Luogu/P3901/P3901.cpp | 71 ++++++++++++++++++++++++++++++++++++ Luogu/P3901/data/P3901_6.in | 3 ++ Luogu/P3901/data/P3901_6.out | 3 ++ Luogu/P3901/data/P3901_8.in | 3 ++ Luogu/P3901/data/P3901_8.out | 3 ++ 5 files changed, 83 insertions(+) create mode 100644 Luogu/P3901/P3901.cpp create mode 100644 Luogu/P3901/data/P3901_6.in create mode 100644 Luogu/P3901/data/P3901_6.out create mode 100644 Luogu/P3901/data/P3901_8.in create mode 100644 Luogu/P3901/data/P3901_8.out diff --git a/Luogu/P3901/P3901.cpp b/Luogu/P3901/P3901.cpp new file mode 100644 index 00000000..44d95fbd --- /dev/null +++ b/Luogu/P3901/P3901.cpp @@ -0,0 +1,71 @@ +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e5 + 5; + +int n, q, a[N], c[N], t; +bool ans[N]; +std::vector> qs; + +inline void add(int x, int &res) { + if (!c[x]++) res++; +} + +inline void del(int x, int &res) { + if (!--c[x]) res--; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> q; + + for (int i = 1; i <= n; i++) { + cin >> a[i]; + } + + t = sqrt(n); + + for (int i = 1, l, r; i <= q; i++) { + cin >> l >> r; + + qs.push_back(std::make_tuple(i, l, r)); + } + + std::sort(qs.begin(), qs.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, x, l, r; + for (auto q : qs) { + std::tie(x, l, r) = q; + + 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[x] = res == (r - l + 1); + } + + for (int i = 1; i <= q; i++) { + cout << (ans[i] ? "Yes" : "No") << endl; + } + + return 0; +} diff --git a/Luogu/P3901/data/P3901_6.in b/Luogu/P3901/data/P3901_6.in new file mode 100644 index 00000000..a8f68d86 --- /dev/null +++ b/Luogu/P3901/data/P3901_6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:28234ac4abf554f2a88292aa4fb2426f48936620287dfcc005e04deefdc6e034 +size 1346189 diff --git a/Luogu/P3901/data/P3901_6.out b/Luogu/P3901/data/P3901_6.out new file mode 100644 index 00000000..5e147091 --- /dev/null +++ b/Luogu/P3901/data/P3901_6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cd92de1a9dbb8a0be379908c1d1395602e2b760effd11a683c5bacdae5c29030 +size 278000 diff --git a/Luogu/P3901/data/P3901_8.in b/Luogu/P3901/data/P3901_8.in new file mode 100644 index 00000000..17e0e51a --- /dev/null +++ b/Luogu/P3901/data/P3901_8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dc853ae36c080bbf3677213fd8ced59d494215ddd89765738902ec65e3d1ddb8 +size 1657161 diff --git a/Luogu/P3901/data/P3901_8.out b/Luogu/P3901/data/P3901_8.out new file mode 100644 index 00000000..de567296 --- /dev/null +++ b/Luogu/P3901/data/P3901_8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:45983447eb4f85d4cae4ac838d3987bff178e865375ab19a790b52487bcec1e1 +size 292204