This documentation is automatically generated by online-judge-tools/verification-helper
View the Project on GitHub kmyk/competitive-programming-library
int sa_lower_bound(string const & s, vector<int> const & sa, string const & t) { // returns an index on suffix array int n = s.size(); int l = 0, r = n+1; // (l, r] while (l + 1 < r) { int m = (l + r) / 2; (s.compare(sa[m], string::npos, t) < 0 ? l : r) = m; } return r; } int sa_prefix_upper_bound(string const & s, vector<int> const & sa, string const & t) { // returns an index on suffix array int n = s.size(); int l = 0, r = n+1; // (l, r] while (l + 1 < r) { int m = (l + r) / 2; (s.compare(sa[m], t.size(), t) <= 0 ? l : r) = m; } return r; } int sa_match(string const & target, string const & pattern, vector<int> const & sa, segment_tree<int> const & lcp) { // O(m \log n) int l = sa_lower_bound(target, sa, pattern); int r = sa_prefix_upper_bound(target, sa, pattern); return r - l; }
#line 1 "old/suffix-array.inc.cpp" int sa_lower_bound(string const & s, vector<int> const & sa, string const & t) { // returns an index on suffix array int n = s.size(); int l = 0, r = n+1; // (l, r] while (l + 1 < r) { int m = (l + r) / 2; (s.compare(sa[m], string::npos, t) < 0 ? l : r) = m; } return r; } int sa_prefix_upper_bound(string const & s, vector<int> const & sa, string const & t) { // returns an index on suffix array int n = s.size(); int l = 0, r = n+1; // (l, r] while (l + 1 < r) { int m = (l + r) / 2; (s.compare(sa[m], t.size(), t) <= 0 ? l : r) = m; } return r; } int sa_match(string const & target, string const & pattern, vector<int> const & sa, segment_tree<int> const & lcp) { // O(m \log n) int l = sa_lower_bound(target, sa, pattern); int r = sa_prefix_upper_bound(target, sa, pattern); return r - l; }