# ã¯ã©ã¹ StringAlgorithm - - - æååã¢ã«ã´ãªãºã è©°ãåããã§ãã æååã«é¢ããæ§ã ãªã¢ã«ã´ãªãºã ãå ¥ã£ã¦ãã¾ãã ## suffixArray ```Java // (1) public static int[] suffixArray(java.lang.String s) // (2) public static int[] suffixArray(char[] s) // (3) public static int[] suffixArray(int[] s) // (4) public static int[] suffixArray(int[] s, int upper) ``` é·ã $n$ ã®æåå `s` ã®Suffix Arrayã¨ãã¦ãé·ã $n$ ã®inté åãè¿ãã Suffix Array `sa`㯠$(0,1,\ldots ,n-1)$ ã®é åã§ãã£ã¦ãå $i=0,1,\cdots , n-2$ ã«ã¤ã㦠`s[sa[i]..n) < s[sa[i+1]..n)` ãæºãããã®ã ### å¶ç´ - $0\le n\le 10^8$ - (4) $0\le \mathrm{upper}<10^8$ - (4) $s$ ã®ãã¹ã¦ã®è¦ç´ $x$ ã«ã¤ã㦠$0\le x\le \mathrm{upper}$ ### è¨ç®é - (1) (2) $O(n)$ - (3) æé $O(n\log n)$ 空é $O(n)$ - (4) $O(n+\mathrm{upper})$ ## lcpArray ```Java // (1) public static int[] lcpArray(java.lang.String s, int[] sa) // (2) public static int[] lcpArray(char[] s, int[] sa) // (3) public static int[] lcpArray(int[] s, int[] sa) ``` é·ã $n$ ã®æåå `s` ã®LCP Arrayã¨ãã¦ãé·ã $n-1$ ã®é åãè¿ãã$i$ çªç®ã®è¦ç´ 㯠`s[sa[i]..n), s[sa[i+1]..n)` ã® LCP(Longest Common Prefix) ã®é·ãã ### å¶ç´ - `sa` 㯠`s` ã®Suffix Array - $1 \le n \le 10^8$ ### è¨ç®é - $O(n)$ ### 使ç¨ä¾ [[https://atcoder.jp/contests/practice2/submissions/16585271]] ## zAlgorithm ```Java // (1) public static int[] zAlgorithm(java.lang.String s) // (2) public static int[] zAlgorithm(char[] s) // (3) public static int[] zAlgorithm(int[] s) ``` å ¥åã®é·ãã $n$ ã¨ãã¦ãé·ã $n$ ã®é åãè¿ãã $i$çªç®ã®è¦ç´ 㯠`s[0..n)` 㨠`s[i..n)` ã®LCP(Longest Common Prefix)ã®é·ãã ### å¶ç´ - $0\le n\le 10^8$ ### è¨ç®é - $O(n)$