0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-19 01:25:25 +00:00

#3751. 「SDOI2009」HH 的项链

https://loj.ac/s/1474109
This commit is contained in:
Baoshuo Ren 2022-06-01 21:14:47 +08:00
parent ad40a7866b
commit c1149a9c83
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
21 changed files with 133 additions and 0 deletions

73
LibreOJ/3751/3751.cpp Normal file
View File

@ -0,0 +1,73 @@
#include <iostream>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 50005,
M = 200005,
S = 1e6 + 5;
int n, m, a[N], c[S], t, ans[M];
std::vector<std::tuple<int, int, int>> q;
inline int get(int x) {
return x / t;
}
inline void add(int x, int& r) {
if (!c[x]++) r++;
}
inline void del(int x, int& r) {
if (!--c[x]) r--;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
t = sqrt(n);
cin >> m;
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 = get(std::get<1>(a)),
q = get(std::get<1>(b));
return p == q ? std::get<2>(a) < std::get<2>(b) : p < q;
});
for (int k = 0, i = 0, j = 1, res = 0, id, l, r; k < q.size(); k++) {
std::tie(id, l, r) = q[k];
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;
}

BIN
LibreOJ/3751/data/1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3751/data/1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3751/data/10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3751/data/10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3751/data/2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3751/data/2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3751/data/3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3751/data/3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3751/data/4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3751/data/4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3751/data/5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3751/data/5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3751/data/6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3751/data/6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3751/data/7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3751/data/7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3751/data/8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3751/data/8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3751/data/9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/3751/data/9.out (Stored with Git LFS) Normal file

Binary file not shown.