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