diff --git a/S2OJ/1746/1746.cpp b/S2OJ/1746/1746.cpp new file mode 100644 index 00000000..8694f123 --- /dev/null +++ b/S2OJ/1746/1746.cpp @@ -0,0 +1,101 @@ +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 300005; + +int q, st[N << 1][20]; +std::string s; + +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; + } + } + + // for (int i = 0; i < n; i++) { + // p[i] = p[i * 2 + 2] / 2; + // } + + // p.resize(n); + + return p; +} + +int query(int l, int r) { + if (l > r) return 1; + int k = std::__lg(r - l + 1); + return std::max(st[l][k], st[r - (1 << k) + 1][k]); +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> s >> q; + + auto p = manacher(s); + int n = s.size(); + int t = std::__lg(p.size()); + + for (int i = 1; i <= p.size(); i++) { + st[i][0] = p[i - 1]; + } + + for (int i = 1; i <= t; i++) { + for (int j = 1; j <= p.size() - (1 << i) + 1; j++) { + st[j][i] = std::max(st[j][i - 1], st[j + (1 << (i - 1))][i - 1]); + } + } + + while (q--) { + int ql, qr; + + cin >> ql >> qr; + + ql = (ql + 1) * 2 + 1; + qr = (qr + 1) * 2 + 1; + + int l = 1, + r = qr - ql + 1, + res = 1; + + while (l <= r) { + int mid = l + r >> 1; + + if (query(ql + mid - 1, qr - mid + 1) - 1 >= mid) { + res = mid; + l = mid + 1; + } else { + r = mid - 1; + } + } + + cout << res << endl; + } + + return 0; +} diff --git a/S2OJ/1746/data/ex_palindrome1.in b/S2OJ/1746/data/ex_palindrome1.in new file mode 100644 index 00000000..5bed569c --- /dev/null +++ b/S2OJ/1746/data/ex_palindrome1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:71dd4440a16e7b8d2341c517bb247578a937105a06fd41afeb2b402097beef39 +size 28 diff --git a/S2OJ/1746/data/ex_palindrome1.out b/S2OJ/1746/data/ex_palindrome1.out new file mode 100644 index 00000000..42cb0878 --- /dev/null +++ b/S2OJ/1746/data/ex_palindrome1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:95ae9b77319e46afa12720f981d3e3a84a1c958396b9cdcf9b29b1333aa13b23 +size 10 diff --git a/S2OJ/1746/data/ex_palindrome2.in b/S2OJ/1746/data/ex_palindrome2.in new file mode 100644 index 00000000..4f08e004 --- /dev/null +++ b/S2OJ/1746/data/ex_palindrome2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:831fb56a0eb24f4c6b994da8670aaead1003510706cd7dfd310d984a019f7b96 +size 77 diff --git a/S2OJ/1746/data/ex_palindrome2.out b/S2OJ/1746/data/ex_palindrome2.out new file mode 100644 index 00000000..ab7552cd --- /dev/null +++ b/S2OJ/1746/data/ex_palindrome2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6ec60399e1bda2d7d68203aed02d9216f5e87ef9ef7413806a475141e60db065 +size 20 diff --git a/S2OJ/1746/data/ex_palindrome3.in b/S2OJ/1746/data/ex_palindrome3.in new file mode 100644 index 00000000..c9a9547c --- /dev/null +++ b/S2OJ/1746/data/ex_palindrome3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:31d1e13a0ac550c2d7b8b41a8a3a2436630953b1f9c8f4e23d12ac166835c786 +size 683 diff --git a/S2OJ/1746/data/ex_palindrome3.out b/S2OJ/1746/data/ex_palindrome3.out new file mode 100644 index 00000000..dc2287b9 --- /dev/null +++ b/S2OJ/1746/data/ex_palindrome3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a18b3a4e07deeed26a05e6fe7e777ff13bf439bbb29a6b3a01112b40a9d40a58 +size 200 diff --git a/S2OJ/1746/data/ex_palindrome4.in b/S2OJ/1746/data/ex_palindrome4.in new file mode 100644 index 00000000..70af5855 --- /dev/null +++ b/S2OJ/1746/data/ex_palindrome4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fc9985ea237d9d8c2008c5170b21b17f7f27c3f677c515e5769b605a3bbf6822 +size 94107 diff --git a/S2OJ/1746/data/ex_palindrome4.out b/S2OJ/1746/data/ex_palindrome4.out new file mode 100644 index 00000000..db9d6e4d --- /dev/null +++ b/S2OJ/1746/data/ex_palindrome4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a2040e01fdf935aa9906ce73f333aa5e21be491bf6bcca5ca828a0588377dde0 +size 42629 diff --git a/S2OJ/1746/data/palindrome1.in b/S2OJ/1746/data/palindrome1.in new file mode 100644 index 00000000..600761c7 --- /dev/null +++ b/S2OJ/1746/data/palindrome1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d1b45c096cad9ec958ef588cd86d06dfe906a6df9140c844ce10f27226ac8777 +size 684 diff --git a/S2OJ/1746/data/palindrome1.out b/S2OJ/1746/data/palindrome1.out new file mode 100644 index 00000000..e45ddf3a --- /dev/null +++ b/S2OJ/1746/data/palindrome1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e3345fe07bf9408058691f322261531048a253546fdca2abab21e8ce5cce55b8 +size 267 diff --git a/S2OJ/1746/data/palindrome10.in b/S2OJ/1746/data/palindrome10.in new file mode 100644 index 00000000..debb66c5 --- /dev/null +++ b/S2OJ/1746/data/palindrome10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b258ee10b04229b154c6fc9c7b9a35171245487da15a604d0d3a9743654bd4f0 +size 4277629 diff --git a/S2OJ/1746/data/palindrome10.out b/S2OJ/1746/data/palindrome10.out new file mode 100644 index 00000000..630ff71f --- /dev/null +++ b/S2OJ/1746/data/palindrome10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b60f6088c4638fe36ecb6d36e2d4d4d622815a7345178356007d8f5ea10c09b9 +size 1768171 diff --git a/S2OJ/1746/data/palindrome2.in b/S2OJ/1746/data/palindrome2.in new file mode 100644 index 00000000..b3c84362 --- /dev/null +++ b/S2OJ/1746/data/palindrome2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5dbc9565efbd0f8934ff6d78e794d438c80831a0ea25d79a5aaa8fd65b34596d +size 683 diff --git a/S2OJ/1746/data/palindrome2.out b/S2OJ/1746/data/palindrome2.out new file mode 100644 index 00000000..c70fb631 --- /dev/null +++ b/S2OJ/1746/data/palindrome2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:652edb7aac8738aae13eeb7c5d018ed4826bc6ed279fc083c713cf12b15ac8a6 +size 279 diff --git a/S2OJ/1746/data/palindrome3.in b/S2OJ/1746/data/palindrome3.in new file mode 100644 index 00000000..73ba6c50 --- /dev/null +++ b/S2OJ/1746/data/palindrome3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cf2cde9def17caaf0c9cae500100db85ef8a8bfd3b81b6e1a73eebc60bc2a992 +size 41753 diff --git a/S2OJ/1746/data/palindrome3.out b/S2OJ/1746/data/palindrome3.out new file mode 100644 index 00000000..4e01f166 --- /dev/null +++ b/S2OJ/1746/data/palindrome3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d1a55e3d4aa776c8f8a8ace98f94a9ce9ce30ecf3e1484840d599be6e77a5f02 +size 17261 diff --git a/S2OJ/1746/data/palindrome4.in b/S2OJ/1746/data/palindrome4.in new file mode 100644 index 00000000..3f45d41f --- /dev/null +++ b/S2OJ/1746/data/palindrome4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1e91da90e4df3f9ee5c9e0cb63d4cc816eae4e93abd9f80cfb715afff42f3e7b +size 41768 diff --git a/S2OJ/1746/data/palindrome4.out b/S2OJ/1746/data/palindrome4.out new file mode 100644 index 00000000..5de2315d --- /dev/null +++ b/S2OJ/1746/data/palindrome4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0bf4ac8b4c1962ff5f53419d11e6d839c00096fdef647af70a967e96720859b2 +size 17114 diff --git a/S2OJ/1746/data/palindrome5.in b/S2OJ/1746/data/palindrome5.in new file mode 100644 index 00000000..23be8fd4 --- /dev/null +++ b/S2OJ/1746/data/palindrome5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1ea32f35a94cd7e28cfacf371d2e44fa0c995823c2aba2102a21e22196200a15 +size 237664 diff --git a/S2OJ/1746/data/palindrome5.out b/S2OJ/1746/data/palindrome5.out new file mode 100644 index 00000000..20552f4d --- /dev/null +++ b/S2OJ/1746/data/palindrome5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3b56a4d40fd194b87f3a958bfb04937077b751863a582539e58842b195bb2bb0 +size 97048 diff --git a/S2OJ/1746/data/palindrome6.in b/S2OJ/1746/data/palindrome6.in new file mode 100644 index 00000000..1d919d03 --- /dev/null +++ b/S2OJ/1746/data/palindrome6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8795dd66f2c00d7133221ec1f0d3011733ec317c8a477e3248eaf7bd6bcf3695 +size 237638 diff --git a/S2OJ/1746/data/palindrome6.out b/S2OJ/1746/data/palindrome6.out new file mode 100644 index 00000000..d2be6098 --- /dev/null +++ b/S2OJ/1746/data/palindrome6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:73a84297d3975038e42518b130d1ec2ab263a0440c4baa363be65eede6d0f570 +size 97182 diff --git a/S2OJ/1746/data/palindrome7.in b/S2OJ/1746/data/palindrome7.in new file mode 100644 index 00000000..cffc0180 --- /dev/null +++ b/S2OJ/1746/data/palindrome7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f2b0c0ffa2581d8c507a2be4886237a2b4af42ee58936c5342965ae7e9b91a6d +size 4277630 diff --git a/S2OJ/1746/data/palindrome7.out b/S2OJ/1746/data/palindrome7.out new file mode 100644 index 00000000..f9df5169 --- /dev/null +++ b/S2OJ/1746/data/palindrome7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:520738926b790aec71c423448566e5de47b4cb430484562d28af0528de801381 +size 1774471 diff --git a/S2OJ/1746/data/palindrome8.in b/S2OJ/1746/data/palindrome8.in new file mode 100644 index 00000000..6bc52ef8 --- /dev/null +++ b/S2OJ/1746/data/palindrome8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b81047bc19dd317171967417560d290111bc4edef37dfa2531a9e3634606534a +size 4278273 diff --git a/S2OJ/1746/data/palindrome8.out b/S2OJ/1746/data/palindrome8.out new file mode 100644 index 00000000..e73994ce --- /dev/null +++ b/S2OJ/1746/data/palindrome8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ba0bb315b5b6307b247c443b67b30982d572ef3e3f132394989fabb5746138a1 +size 1771259 diff --git a/S2OJ/1746/data/palindrome9.in b/S2OJ/1746/data/palindrome9.in new file mode 100644 index 00000000..437d05d1 --- /dev/null +++ b/S2OJ/1746/data/palindrome9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fc4d2929d3aed27c5fcde8a665b8958fe4d766a72755d3ec30f8b661c31d29e1 +size 4277704 diff --git a/S2OJ/1746/data/palindrome9.out b/S2OJ/1746/data/palindrome9.out new file mode 100644 index 00000000..4fc07c59 --- /dev/null +++ b/S2OJ/1746/data/palindrome9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:75a6a5626fa6a142764fcbc963900708a0fcdc78e9c648b62f5486916f8d30a1 +size 1770733 diff --git a/S2OJ/1746/data/problem.conf b/S2OJ/1746/data/problem.conf new file mode 100644 index 00000000..9b8bd847 --- /dev/null +++ b/S2OJ/1746/data/problem.conf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f1ea6a377d3c5566e5724efe81935a9fe567df2da9ad4fe708f1174a6028e7e1 +size 189