diff --git a/S2OJ/639/639.cpp b/S2OJ/639/639.cpp new file mode 100644 index 00000000..fdf4581e --- /dev/null +++ b/S2OJ/639/639.cpp @@ -0,0 +1,72 @@ +#include +#include +#include + +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(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(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; +} diff --git a/S2OJ/639/data/problem.conf b/S2OJ/639/data/problem.conf new file mode 100644 index 00000000..582b1383 --- /dev/null +++ b/S2OJ/639/data/problem.conf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5e4885135a045475028e2f7e52a7d6b673352188364cce5bb240010c424fd633 +size 745 diff --git a/S2OJ/639/data/string1.in b/S2OJ/639/data/string1.in new file mode 100644 index 00000000..9c423352 --- /dev/null +++ b/S2OJ/639/data/string1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9c1487349e6215733a9a486c6bb2c63ce92fc4cdbe89b2a0897fdfb7c7ecc49b +size 21 diff --git a/S2OJ/639/data/string1.out b/S2OJ/639/data/string1.out new file mode 100644 index 00000000..c35e4db8 --- /dev/null +++ b/S2OJ/639/data/string1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f4a366de1c2699ac2dedb4c755156c9e60757bb54807547c29b3562bd0a7e9ab +size 4 diff --git a/S2OJ/639/data/string10.in b/S2OJ/639/data/string10.in new file mode 100644 index 00000000..ee1eb26a --- /dev/null +++ b/S2OJ/639/data/string10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:529f2e8f44039e1cd00fd00121f95a0843c3ad9f6e4902629dad650da8b42da2 +size 100001 diff --git a/S2OJ/639/data/string10.out b/S2OJ/639/data/string10.out new file mode 100644 index 00000000..0369cad5 --- /dev/null +++ b/S2OJ/639/data/string10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:60999753f8412eee7752e94a1e955fd47844dd1caf400f4ecb20efcdd3083507 +size 10 diff --git a/S2OJ/639/data/string11.in b/S2OJ/639/data/string11.in new file mode 100644 index 00000000..e88d2ba9 --- /dev/null +++ b/S2OJ/639/data/string11.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:178bdbeaf529379353e91f3bb222cd881c10000c307aa4d59110eb3e91ccb7cd +size 1000001 diff --git a/S2OJ/639/data/string11.out b/S2OJ/639/data/string11.out new file mode 100644 index 00000000..3de92162 --- /dev/null +++ b/S2OJ/639/data/string11.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2a132603f2eb160b71abfda844c1f2d80ce84afcf11935fb804c512caef098d7 +size 10 diff --git a/S2OJ/639/data/string12.in b/S2OJ/639/data/string12.in new file mode 100644 index 00000000..be3c9887 --- /dev/null +++ b/S2OJ/639/data/string12.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ecb46111aaaffe70f181bb696419f1dc1c43acaf84ec64640c1449d6f15699db +size 1000001 diff --git a/S2OJ/639/data/string12.out b/S2OJ/639/data/string12.out new file mode 100644 index 00000000..7b97682d --- /dev/null +++ b/S2OJ/639/data/string12.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f0d22076c9f138b1f799e55a4bcf41306324ff22e28149f148edf6a734d128d7 +size 10 diff --git a/S2OJ/639/data/string2.in b/S2OJ/639/data/string2.in new file mode 100644 index 00000000..d339ae0c --- /dev/null +++ b/S2OJ/639/data/string2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1881712b1c2a511d682e9964b8d81a11cf021bb70e553d0fc5771558daee1257 +size 21 diff --git a/S2OJ/639/data/string2.out b/S2OJ/639/data/string2.out new file mode 100644 index 00000000..7addf8f8 --- /dev/null +++ b/S2OJ/639/data/string2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:32c2643e0dc65524c9f1f6f9f00937322fd68d59986bc381d9ff2285d23e353d +size 3 diff --git a/S2OJ/639/data/string3.in b/S2OJ/639/data/string3.in new file mode 100644 index 00000000..36c637a0 --- /dev/null +++ b/S2OJ/639/data/string3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:396f3fbb9c99187716a1ad9939a62f1449698d2ee07f9a2273db0018bd01d60c +size 201 diff --git a/S2OJ/639/data/string3.out b/S2OJ/639/data/string3.out new file mode 100644 index 00000000..0cf6a025 --- /dev/null +++ b/S2OJ/639/data/string3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0670c5c17fd8bf1cf343db1720e9f8599eeabb9b32e85cf3999df0f794c021ee +size 10 diff --git a/S2OJ/639/data/string4.in b/S2OJ/639/data/string4.in new file mode 100644 index 00000000..d65116d4 --- /dev/null +++ b/S2OJ/639/data/string4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ccd17374d47af972b466c67afb3c2a47921d2c31911009589d46dd62f9a0dfe5 +size 201 diff --git a/S2OJ/639/data/string4.out b/S2OJ/639/data/string4.out new file mode 100644 index 00000000..b22fba1e --- /dev/null +++ b/S2OJ/639/data/string4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e02afadb5759fbf36eb5559836195dee5b23984afd6d166d8481e64dc68c2f4a +size 9 diff --git a/S2OJ/639/data/string5.in b/S2OJ/639/data/string5.in new file mode 100644 index 00000000..1c13f568 --- /dev/null +++ b/S2OJ/639/data/string5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:784c0af9e209207e36c320c1f46dc1647f9396915d3f9c2b0ba9d6d3385f5268 +size 201 diff --git a/S2OJ/639/data/string5.out b/S2OJ/639/data/string5.out new file mode 100644 index 00000000..c4e15e2a --- /dev/null +++ b/S2OJ/639/data/string5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:18f5cdcb3cfbcab9e388f684f873bcce494b8316bb0507cedc59ba2a93114000 +size 9 diff --git a/S2OJ/639/data/string6.in b/S2OJ/639/data/string6.in new file mode 100644 index 00000000..4786764d --- /dev/null +++ b/S2OJ/639/data/string6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e2084970bd503f5218b2a58ab58f9642f77743064ed299213471f04641ece8ba +size 2001 diff --git a/S2OJ/639/data/string6.out b/S2OJ/639/data/string6.out new file mode 100644 index 00000000..e1a950f0 --- /dev/null +++ b/S2OJ/639/data/string6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:970766a8f866cb898ae9209024c0482c20ccdc20972a2f39e2011251beea3472 +size 10 diff --git a/S2OJ/639/data/string7.in b/S2OJ/639/data/string7.in new file mode 100644 index 00000000..d058f1be --- /dev/null +++ b/S2OJ/639/data/string7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f8f097e3c6076db251c5aa04f2b9dcb2ea4b22401b31ad0edb9001f787fa9dff +size 2001 diff --git a/S2OJ/639/data/string7.out b/S2OJ/639/data/string7.out new file mode 100644 index 00000000..46fdd44f --- /dev/null +++ b/S2OJ/639/data/string7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fda6cbfca6c63495bf0675950fb75af2950322389ca9b2ea3f5fa598ebf3ea2a +size 10 diff --git a/S2OJ/639/data/string8.in b/S2OJ/639/data/string8.in new file mode 100644 index 00000000..82d24f29 --- /dev/null +++ b/S2OJ/639/data/string8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:34de531f5f3c8cee34a070c21a850e24276b8b85a593e38c0e4862e94a29bd01 +size 2001 diff --git a/S2OJ/639/data/string8.out b/S2OJ/639/data/string8.out new file mode 100644 index 00000000..ecc8b0b9 --- /dev/null +++ b/S2OJ/639/data/string8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7f706852198f21848dc409819cb1787e827af627c60ca425f20110d1ca8b64a2 +size 9 diff --git a/S2OJ/639/data/string9.in b/S2OJ/639/data/string9.in new file mode 100644 index 00000000..20bd6f51 --- /dev/null +++ b/S2OJ/639/data/string9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:821a045585df1a94a498782f111988af5336c65d2f32fed9dd2e734c27afe5f3 +size 100001 diff --git a/S2OJ/639/data/string9.out b/S2OJ/639/data/string9.out new file mode 100644 index 00000000..8df3b224 --- /dev/null +++ b/S2OJ/639/data/string9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ff3ce2a2c60bd4e102cd7a0690630ab0804f03d01541a0512dcfcb4fbb09a650 +size 10