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

#639. 串一串(string)

https://sjzezoj.com/submission/71323
This commit is contained in:
Baoshuo Ren 2023-02-20 19:07:00 +08:00
parent a9dacf2e67
commit 60e8368d36
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
26 changed files with 147 additions and 0 deletions

72
S2OJ/639/639.cpp Normal file
View File

@ -0,0 +1,72 @@
#include <iostream>
#include <algorithm>
#include <string>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e6 + 5,
M = 62;
const int mod = 998244353;
int n, a[N], pre[N][M], suf[N][M], f1[M][M], f2[M][M], same, ans;
std::string s;
int c2(int x) {
return static_cast<long long>(x) * (x - 1) / 2 % mod;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> s;
n = s.size();
std::transform(s.rbegin(), s.rend(), a + 1, [&](char c) -> int {
if ('a' <= c && c <= 'z') return c - 'a';
if ('A' <= c && c <= 'Z') return c - 'A' + 26;
return c - '0' + 52;
});
for (int i = 1; i <= n; i++) {
std::copy(std::begin(pre[i - 1]), std::end(pre[i - 1]), std::begin(pre[i]));
pre[i][a[i]]++;
}
for (int i = n; i; i--) {
std::copy(std::begin(suf[i + 1]), std::end(suf[i + 1]), std::begin(suf[i]));
suf[i][a[i]]++;
}
for (int j = 0; j < M; ++j) {
same = (same + c2(pre[n][j])) % mod;
}
for (int i = 1; i <= n; i++) {
same = ((same - suf[i + 1][a[i]]) % mod + mod) % mod;
for (int j = 0; j < M; j++) {
if (j == a[i]) continue;
ans = (ans + static_cast<long long>(f2[j][a[i]]) * ((c2(n - i - suf[i + 1][a[i]] - suf[i + 1][j]) - ((same - (c2(suf[i + 1][j]) + c2(suf[i + 1][a[i]]))) % mod + mod) % mod) % mod + mod) % mod) % mod;
}
for (int j = 0; j < M; j++) {
if (j == a[i]) continue;
f2[a[i]][j] = (f2[a[i]][j] + f1[a[i]][j]) % mod;
}
for (int j = 0; j < M; j++) {
if (j == a[i]) continue;
f1[j][a[i]] = (f1[j][a[i]] + pre[i - 1][j]) % mod;
}
}
cout << ans << endl;
return 0;
}

BIN
S2OJ/639/data/problem.conf (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/639/data/string1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/639/data/string1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/639/data/string10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/639/data/string10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/639/data/string11.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/639/data/string11.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/639/data/string12.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/639/data/string12.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/639/data/string2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/639/data/string2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/639/data/string3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/639/data/string3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/639/data/string4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/639/data/string4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/639/data/string5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/639/data/string5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/639/data/string6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/639/data/string6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/639/data/string7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/639/data/string7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/639/data/string8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/639/data/string8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/639/data/string9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/639/data/string9.out (Stored with Git LFS) Normal file

Binary file not shown.