This documentation is automatically generated by online-judge-tools/verification-helper
View the Project on GitHub tatyam-prime/ICPC_notebook
#include "src/string/Zalgorithm.hpp"
vector<ll> Z(string s)
// Z[i] := LCP(s, s[i:]) // abacaba -> 7010301 auto Z(string s) { ll n = sz(s), l = -1, r = -1; vector<ll> z(n, n); rep(i, 1, n) { ll& x = z[i] = i < r ? min(r - i, z[i - l]) : 0; while(i + x < n && s[i + x] == s[x]) x++; if(i + x > r) l = i, r = i + x; } return z; }
#line 1 "src/string/Zalgorithm.hpp" // Z[i] := LCP(s, s[i:]) // abacaba -> 7010301 auto Z(string s) { ll n = sz(s), l = -1, r = -1; vector<ll> z(n, n); rep(i, 1, n) { ll& x = z[i] = i < r ? min(r - i, z[i - l]) : 0; while(i + x < n && s[i + x] == s[x]) x++; if(i + x > r) l = i, r = i + x; } return z; }