mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-24 03:31:59 +00:00
parent
b04f707972
commit
c792347fc7
71
Luogu/P3901/P3901.cpp
Normal file
71
Luogu/P3901/P3901.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
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<std::tuple<int, int, int>> 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;
|
||||
}
|
BIN
Luogu/P3901/data/P3901_6.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P3901/data/P3901_6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3901/data/P3901_6.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P3901/data/P3901_6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3901/data/P3901_8.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P3901/data/P3901_8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P3901/data/P3901_8.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P3901/data/P3901_8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user