0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 16:28:47 +00:00

2120. 数颜色

https://hydro.ac/d/bzoj/record/6322f0d432ae6c3198cca1a8
This commit is contained in:
Baoshuo Ren 2022-09-15 17:31:56 +08:00
parent 273f8ac7ff
commit 882d6e0cd9
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
41 changed files with 218 additions and 0 deletions

98
BZOJ/2120/2120.cpp Normal file
View File

@ -0,0 +1,98 @@
#include <iostream>
#include <algorithm>
#include <tuple>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 200005,
M = 1e6 + 5;
int n, m, a[N], cnt[M], t, ans[N];
std::vector<std::pair<int, int>> c;
std::vector<std::tuple<int, int, int, int>> q;
inline void add(int x, int &res) {
if (!cnt[x]++) res++;
}
inline void del(int x, int &res) {
if (!--cnt[x]) res--;
}
inline void tim(int x, int i, int j, int &res) {
if (j <= c[x].first && c[x].first <= i) {
del(a[c[x].first], res);
add(c[x].second, res);
}
std::swap(a[c[x].first], c[x].second);
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
c.push_back(std::make_pair(0, 0));
for (int i = 1; i <= m; i++) {
char op;
int x, y;
cin >> op >> x >> y;
if (op == 'Q') {
q.push_back(std::make_tuple(i, x, y, c.size() - 1));
} else { // op == 'C'
c.push_back(std::make_pair(x, y));
}
}
t = 2609;
std::sort(q.begin(), q.end(), [&](auto a, auto b) {
int p = std::get<1>(a) / t,
q = std::get<1>(b) / t;
int x = std::get<2>(a) / t,
y = std::get<2>(b) / t;
return p == q
? x == y
? std::get<3>(a) < std::get<3>(b)
: x < y
: p < q;
});
int i = 0, j = 1, now = 0, res = 0;
for (auto &e : q) {
int id, l, r, t2;
std::tie(id, l, r, t2) = 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);
while (now < t2) tim(++now, i, j, res);
while (now > t2) tim(now--, i, j, res);
ans[id] = res;
}
std::sort(q.begin(), q.end(), [&](auto a, auto b) {
return std::get<0>(a) < std::get<0>(b);
});
for (auto &e : q) {
cout << ans[std::get<0>(e)] << endl;
}
return 0;
}

BIN
BZOJ/2120/data/1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/11.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/11.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/12.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/12.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/13.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/13.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/14.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/14.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/15.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/15.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/16.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/16.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/17.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/17.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/18.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/18.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/19.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/19.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/20.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/20.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/2120/data/9.out (Stored with Git LFS) Normal file

Binary file not shown.