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

2821. 作诗(Poetize)

https://hydro.ac/d/bzoj/record/62fcd479e42c71bad9ed829f
This commit is contained in:
Baoshuo Ren 2022-08-17 19:44:22 +08:00
parent b2241462af
commit 2882055cf0
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
21 changed files with 171 additions and 0 deletions

111
BZOJ/2821/2821.cpp Normal file
View File

@ -0,0 +1,111 @@
#include <iostream>
#include <cmath>
#include <cstring>
using std::cin;
using std::cout;
const char endl = '\n';
constexpr int N = 1e5 + 5,
M = 1005;
int n, c, m, a[N], cnt[M][N], ans[M][N], res;
int t, b, st[N], ed[N], pos[N], h[N];
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> c >> m;
t = std::sqrt(n);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (b = 1;; b++) {
st[b] = (b - 1) * t + 1;
ed[b] = std::min(n, b * t);
if (b * t >= n) break;
}
for (int i = 1; i <= b; i++) {
for (int j = st[i]; j <= ed[i]; j++) {
pos[j] = i;
cnt[i][a[j]]++;
}
}
for (int i = 1; i <= b; i++) {
for (int j = 0; j <= c; j++) {
cnt[i][j] += cnt[i - 1][j];
}
}
for (int i = 1; i <= b; i++) {
for (int j = i; j <= b; j++) {
ans[i][j] = ans[i][j - 1];
for (int k = st[j]; k <= ed[j]; k++) {
h[a[k]]++;
if (h[a[k]] % 2 == 0) ans[i][j]++;
else if (h[a[k]] >= 3) ans[i][j]--;
}
}
memset(h, 0x00, sizeof(h));
}
while (m--) {
int l, r;
cin >> l >> r;
l = (l + res) % n + 1;
r = (r + res) % n + 1;
if (l > r) std::swap(l, r);
if (pos[l] == pos[r]) {
res = 0;
for (int i = l; i <= r; i++) {
h[a[i]]++;
if (h[a[i]] % 2 == 0) res++;
else if (h[a[i]] >= 3) res--;
}
for (int i = l; i <= r; i++) h[a[i]]--;
} else {
res = ans[pos[l] + 1][pos[r] - 1];
for (int i = l; i <= ed[pos[l]]; i++) {
h[a[i]]++;
int x = cnt[pos[r] - 1][a[i]] - cnt[pos[l]][a[i]];
if ((h[a[i]] + x) % 2 == 0) res++;
else if (h[a[i]] + x >= 3) res--;
}
for (int i = st[pos[r]]; i <= r; i++) {
h[a[i]]++;
int x = cnt[pos[r] - 1][a[i]] - cnt[pos[l]][a[i]];
if ((h[a[i]] + x) % 2 == 0) res++;
else if (h[a[i]] + x >= 3) res--;
}
for (int i = l; i <= ed[pos[l]]; i++) h[a[i]]--;
for (int i = st[pos[r]]; i <= r; i++) h[a[i]]--;
}
cout << res << endl;
}
return 0;
}

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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.