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

#1446. 数列分块入门8

https://sjzezoj.com/submission/53259
This commit is contained in:
Baoshuo Ren 2022-06-23 10:34:57 +08:00
parent 56c8b7aff7
commit 525c3c6a1a
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
21 changed files with 154 additions and 0 deletions

94
S2OJ/1446/1446.cpp Normal file
View File

@ -0,0 +1,94 @@
#include <iostream>
#include <cmath>
#include <cstring>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e5 + 5;
int n, c, t, a[N], st[N], ed[N], pos[N], rep[N];
inline void pushdown(int x) {
if (rep[x] != -1) {
for (int i = st[x]; i <= ed[x]; i++) a[i] = rep[x];
rep[x] = -1;
}
}
int solve(int l, int r, int c) {
int p = pos[l],
q = pos[r];
int res = 0;
if (p == q) {
pushdown(p);
for (int i = l; i <= r; i++) {
if (a[i] == c) res++;
a[i] = c;
}
return res;
}
pushdown(p);
for (int i = l; i <= ed[p]; i++) {
if (a[i] == c) res++;
a[i] = c;
}
pushdown(q);
for (int i = st[q]; i <= r; i++) {
if (a[i] == c) res++;
a[i] = c;
}
for (int i = p + 1; i <= q - 1; i++) {
if (rep[i] != -1) {
if (rep[i] == c) res += ed[i] - st[i] + 1;
} else {
for (int j = st[i]; j <= ed[i]; j++) {
if (a[j] == c) res++;
a[j] = c;
}
}
rep[i] = c;
}
return res;
}
int main() {
std::ios::sync_with_stdio(false);
memset(rep, 0xff, sizeof(rep));
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
t = std::sqrt(n);
for (c = 1;; c++) {
st[c] = (c - 1) * t + 1;
ed[c] = std::min(n, c * t);
if (c * t >= n) break;
}
for (int i = 1; i <= c; i++) {
for (int j = st[i]; j <= ed[i]; j++) {
pos[j] = i;
}
}
for (int i = 1, l, r, c; i <= n; i++) {
cin >> l >> r >> c;
cout << solve(l, r, c) << endl;
}
return 0;
}

BIN
S2OJ/1446/data/a1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1446/data/a1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1446/data/a10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1446/data/a10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1446/data/a2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1446/data/a2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1446/data/a3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1446/data/a3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1446/data/a4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1446/data/a4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1446/data/a5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1446/data/a5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1446/data/a6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1446/data/a6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1446/data/a7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1446/data/a7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1446/data/a8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1446/data/a8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1446/data/a9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1446/data/a9.out (Stored with Git LFS) Normal file

Binary file not shown.