模板 字尾陣列

2022-04-29 23:57:07 字數 415 閱讀 8573

定義rank[i]表示suffix[i]在所有字尾中的字典序排名;sa[i]表示字典序排名為i的字尾是suffix[sa[i]]

定義height[i]表示排名為i的字尾和排名為i-1的字尾的lcp(最長公共字首)

可以證明,$height[rank[i]]>=height[rank[i-1]]-1$

然後有對於兩個字尾x,y,$lcp(x,y)=min_$

所以預處理乙個st表就可以o(1)查lcp了

可以用倍增+基數排序來求

具體怎麼做還是背板子吧2333

1 inline void

build()m=j;20}

2122

for(int i=1,j=0;i<=n;i++)

29 }

注意rank和tmp開兩倍空間

字尾陣列 模板

char s n 陣列的長度要為兩倍的 int n n全域性變數為字元陣列的長度的 int sa n 2 high n 2 rank n 2 tmp n 2 top n 2 void makesa void lcp int main gets s int len strlen s s len get...

字尾陣列模板

過了期末了,繼續寫acm題 自己寫的字尾陣列模板。k,len,rank,sa,tmp,都要寫在外面,這樣就不用來回折騰了。也是使用倍增法來做的,得到乙個sa,儲存了字尾排在第i位的字尾的起始位置。因為空也算乙個字尾,所以函式中都是 len include include include includ...

模板 字尾陣列

include include includeusing namespace std const int max 20001 int num max int sa max rank max height max int wa max wb max wv max wd max int cmp int ...