From 23566c7db09b9d2fcd28e529309c85aab50e40cc Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Tue, 17 Jan 2023 11:27:34 +0800 Subject: [PATCH] =?UTF-8?q?#1821.=20=E8=8A=B1=E6=B5=B7=E6=BC=AB=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://sjzezoj.com/submission/67054 --- S2OJ/1821/1821.cpp | 71 +++++++++++++++++++++++++++++++++++ S2OJ/1821/data/manacher1.in | 3 ++ S2OJ/1821/data/manacher1.out | 3 ++ S2OJ/1821/data/manacher10.in | 3 ++ S2OJ/1821/data/manacher10.out | 3 ++ S2OJ/1821/data/manacher2.in | 3 ++ S2OJ/1821/data/manacher2.out | 3 ++ S2OJ/1821/data/manacher3.in | 3 ++ S2OJ/1821/data/manacher3.out | 3 ++ S2OJ/1821/data/manacher4.in | 3 ++ S2OJ/1821/data/manacher4.out | 3 ++ S2OJ/1821/data/manacher5.in | 3 ++ S2OJ/1821/data/manacher5.out | 3 ++ S2OJ/1821/data/manacher6.in | 3 ++ S2OJ/1821/data/manacher6.out | 3 ++ S2OJ/1821/data/manacher7.in | 3 ++ S2OJ/1821/data/manacher7.out | 3 ++ S2OJ/1821/data/manacher8.in | 3 ++ S2OJ/1821/data/manacher8.out | 3 ++ S2OJ/1821/data/manacher9.in | 3 ++ S2OJ/1821/data/manacher9.out | 3 ++ S2OJ/1821/data/problem.conf | 3 ++ 22 files changed, 134 insertions(+) create mode 100644 S2OJ/1821/1821.cpp create mode 100644 S2OJ/1821/data/manacher1.in create mode 100644 S2OJ/1821/data/manacher1.out create mode 100644 S2OJ/1821/data/manacher10.in create mode 100644 S2OJ/1821/data/manacher10.out create mode 100644 S2OJ/1821/data/manacher2.in create mode 100644 S2OJ/1821/data/manacher2.out create mode 100644 S2OJ/1821/data/manacher3.in create mode 100644 S2OJ/1821/data/manacher3.out create mode 100644 S2OJ/1821/data/manacher4.in create mode 100644 S2OJ/1821/data/manacher4.out create mode 100644 S2OJ/1821/data/manacher5.in create mode 100644 S2OJ/1821/data/manacher5.out create mode 100644 S2OJ/1821/data/manacher6.in create mode 100644 S2OJ/1821/data/manacher6.out create mode 100644 S2OJ/1821/data/manacher7.in create mode 100644 S2OJ/1821/data/manacher7.out create mode 100644 S2OJ/1821/data/manacher8.in create mode 100644 S2OJ/1821/data/manacher8.out create mode 100644 S2OJ/1821/data/manacher9.in create mode 100644 S2OJ/1821/data/manacher9.out create mode 100644 S2OJ/1821/data/problem.conf diff --git a/S2OJ/1821/1821.cpp b/S2OJ/1821/1821.cpp new file mode 100644 index 00000000..1c839b59 --- /dev/null +++ b/S2OJ/1821/1821.cpp @@ -0,0 +1,71 @@ +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 2e6 + 5; +const int mod = 1e9 + 7; + +std::vector manacher(const std::string &_s) { + int n = _s.size(); + std::string s(n * 2 + 3, '#'); + + for (int i = 0; i < n; i++) { + s[i * 2 + 2] = _s[i]; + } + + s[0] = '^'; + s[n * 2 + 2] = '$'; + + std::vector p(s.size(), 1); + + for (int i = 1, mid = 0, r = 0; i <= n * 2 + 1; i++) { + p[i] = i < r ? std::min(p[mid * 2 - i], r - i) : 1; + + while (s[i - p[i]] == s[i + p[i]]) p[i]++; + + if (i + p[i] - 1 > r) { + r = i + p[i] - 1; + mid = i; + } + } + + return p; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + int n; + long long sum = 0, ans = 0; + std::string s; + + cin >> n >> s; + + auto p = manacher(s); + std::vector pre(p.size()), suf(p.size()); + + for (int i = 2; i < p.size() - 2; i++) { + pre[i - p[i] + 1]++, pre[i + 1]--; + suf[i]++, suf[i + p[i]]--; + ans = (ans + p[i] / 2) % mod; + } + + ans = ans * (ans - 1) / 2; + std::partial_sum(pre.begin(), pre.end(), pre.begin()); + std::partial_sum(suf.begin(), suf.end(), suf.begin()); + + for (int i = 2; i < p.size() - 2; i += 2) { + ans = ((ans - sum * pre[i] % mod) % mod + mod) % mod; + sum = (sum + suf[i]) % mod; + } + + cout << ans << endl; + + return 0; +} diff --git a/S2OJ/1821/data/manacher1.in b/S2OJ/1821/data/manacher1.in new file mode 100644 index 00000000..10f22423 --- /dev/null +++ b/S2OJ/1821/data/manacher1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9fb7f11df9b85661436a71bccf3142042a7bb45ce7a41af134f23eed02030ba7 +size 1006 diff --git a/S2OJ/1821/data/manacher1.out b/S2OJ/1821/data/manacher1.out new file mode 100644 index 00000000..92ec6093 --- /dev/null +++ b/S2OJ/1821/data/manacher1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2ab513b1608dd3d214980f32cdf095ca53e81eec6fc4ded522b7a1541fafc99a +size 5 diff --git a/S2OJ/1821/data/manacher10.in b/S2OJ/1821/data/manacher10.in new file mode 100644 index 00000000..4aa50d97 --- /dev/null +++ b/S2OJ/1821/data/manacher10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8330769fb6d26d397af24737fecdd8e514786de963e6f481061f761698d5ff9a +size 14 diff --git a/S2OJ/1821/data/manacher10.out b/S2OJ/1821/data/manacher10.out new file mode 100644 index 00000000..1d0769d4 --- /dev/null +++ b/S2OJ/1821/data/manacher10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ce516e29a2ccfe4bab40e4e6adab7661cd695680482c00b1faa738fc0df62698 +size 3 diff --git a/S2OJ/1821/data/manacher2.in b/S2OJ/1821/data/manacher2.in new file mode 100644 index 00000000..12f52c83 --- /dev/null +++ b/S2OJ/1821/data/manacher2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:adb5fffd27c4438e0f93f4e8d85568cc2da285d60880d54d1a198f5fb9e379b7 +size 1006 diff --git a/S2OJ/1821/data/manacher2.out b/S2OJ/1821/data/manacher2.out new file mode 100644 index 00000000..91bd7e73 --- /dev/null +++ b/S2OJ/1821/data/manacher2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:95d3a04b18d7334926f301e4e45135d0c89cef70f9a05ff873ab08dd3464f124 +size 4 diff --git a/S2OJ/1821/data/manacher3.in b/S2OJ/1821/data/manacher3.in new file mode 100644 index 00000000..c4192b8c --- /dev/null +++ b/S2OJ/1821/data/manacher3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:66b51ee55d420da10369efcf9638ee5b775b99c6749d0d9a6a68b034a3a03fe4 +size 100004 diff --git a/S2OJ/1821/data/manacher3.out b/S2OJ/1821/data/manacher3.out new file mode 100644 index 00000000..1d470668 --- /dev/null +++ b/S2OJ/1821/data/manacher3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b84d4475de5e2808255628e8a99e733b6ef88cd5325709438f50915f55711e9e +size 10 diff --git a/S2OJ/1821/data/manacher4.in b/S2OJ/1821/data/manacher4.in new file mode 100644 index 00000000..56775163 --- /dev/null +++ b/S2OJ/1821/data/manacher4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:675b5c9e848414455e0bb76fe82ae454d7f5065296f458de2443a3ebe39b29d4 +size 10007 diff --git a/S2OJ/1821/data/manacher4.out b/S2OJ/1821/data/manacher4.out new file mode 100644 index 00000000..64547c5b --- /dev/null +++ b/S2OJ/1821/data/manacher4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:358b48f1ee6547f83215956a0cc8ce5f89776879c7e5534a31f36b8a81db7e36 +size 5 diff --git a/S2OJ/1821/data/manacher5.in b/S2OJ/1821/data/manacher5.in new file mode 100644 index 00000000..ac13a0f1 --- /dev/null +++ b/S2OJ/1821/data/manacher5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6c198b1d493e6ff6e4b850de611588dcaec41db7c6ec4d63085e1a9ea83bc006 +size 49220 diff --git a/S2OJ/1821/data/manacher5.out b/S2OJ/1821/data/manacher5.out new file mode 100644 index 00000000..67ecd556 --- /dev/null +++ b/S2OJ/1821/data/manacher5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:55ff905ceaa7fd7bbf6fa0a54b87e1d1eeea21019b4c42824d2dcf35cb51a6d9 +size 6 diff --git a/S2OJ/1821/data/manacher6.in b/S2OJ/1821/data/manacher6.in new file mode 100644 index 00000000..7923d477 --- /dev/null +++ b/S2OJ/1821/data/manacher6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:477f7a530473fa2a704b47c7a363c4a0f6a3212ae9673a6eff394821b2c86393 +size 100008 diff --git a/S2OJ/1821/data/manacher6.out b/S2OJ/1821/data/manacher6.out new file mode 100644 index 00000000..86824b64 --- /dev/null +++ b/S2OJ/1821/data/manacher6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9b04c99bfba80067c5f3cf02b6d3abd6475aee5294c41c87a07032b564587851 +size 8 diff --git a/S2OJ/1821/data/manacher7.in b/S2OJ/1821/data/manacher7.in new file mode 100644 index 00000000..ae720fa6 --- /dev/null +++ b/S2OJ/1821/data/manacher7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:14e62141f478fd63835b4391044c675bfb11f5d4858e3654a4be15447237017a +size 200008 diff --git a/S2OJ/1821/data/manacher7.out b/S2OJ/1821/data/manacher7.out new file mode 100644 index 00000000..b6d925ce --- /dev/null +++ b/S2OJ/1821/data/manacher7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:932f9ac4ace4618c7590472facf5b27bbbcac390ebc67de2ae363b8de9432afc +size 8 diff --git a/S2OJ/1821/data/manacher8.in b/S2OJ/1821/data/manacher8.in new file mode 100644 index 00000000..cdb7ed07 --- /dev/null +++ b/S2OJ/1821/data/manacher8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3f0e81505c0255993ab653f9fb6123705b8efdf66a1ef52cf7089799c52ca904 +size 200008 diff --git a/S2OJ/1821/data/manacher8.out b/S2OJ/1821/data/manacher8.out new file mode 100644 index 00000000..7b6918ba --- /dev/null +++ b/S2OJ/1821/data/manacher8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f15b3834c0cad33743a5b7cf080bd0314e1338bf32685b2e3ada3e5cd253559c +size 8 diff --git a/S2OJ/1821/data/manacher9.in b/S2OJ/1821/data/manacher9.in new file mode 100644 index 00000000..22e539df --- /dev/null +++ b/S2OJ/1821/data/manacher9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7d16899add880b45ce0dfcdfcb2edc6fe61ebddd3a89e19bb80cae253720ac44 +size 200008 diff --git a/S2OJ/1821/data/manacher9.out b/S2OJ/1821/data/manacher9.out new file mode 100644 index 00000000..ef8e66fc --- /dev/null +++ b/S2OJ/1821/data/manacher9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:63682245f66c26b18545fb9151541518efce0e9ad7ca7a50b708f56d565669bc +size 8 diff --git a/S2OJ/1821/data/problem.conf b/S2OJ/1821/data/problem.conf new file mode 100644 index 00000000..1e9a2943 --- /dev/null +++ b/S2OJ/1821/data/problem.conf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c16de2b67d2e4cf1a4f3e580ef52d3bb4352a122953d16825c7ce55b2fcd039d +size 185