String summary

Meow named on the planet:

  For string matching problem, consider the text string up mode, and then dispose of SA array. Middle with different "baffle character" is to prevent two different string that matches a string ($ ab $, $ aba $). But still a suffix string with another string match many times. For named string that called name $ $ LCP is not less than the length of the string named, you can find the control range of the monotonous stack, for the range named string, statistics are comparable to the color. Recording color precursor can be pre $ $, tree Chairman difference interval $ [l, r] $ $ smaller than the pre $ $ $ L number; may be enumerated by the right end of the interrogation, named for the same string to maintain only the most a right, representing a decrease of one-dimensional arrays can be installed with the tree. For the number of times a name to be called, you can also consider establishing a boundary to query. Provided named string control interval $ [l, r] $, $ X $ Name precursor is $ pre [x] $. Give the name of a named string to contribute, in fact, $ pre [x] \ le l \ le x $, drawing easy to understand. That is, if a named string of r is less than the current $ x $, must not contributing, you can delete contributions. This bar named string contribution meter on the $ l $, the name of the query string contribute $ (pre [x], x] $ when a $ r \> x $ when you fail, you can count shaped array maintained.

difference:

TO:

  For $ len (i) $ total contribution is $ ans = \ frac {(N-1) * N * (N + 1)} {2} $, $ subtracted LCP consider each suffix $ $ $ appears LCP how many times. Enumeration range $ i \ neq j $ so that any point on will be to enumerate, so to account for the $ rank $ sort is the same. Then ask each range $ height $ is able to control the number of $ lcp $ this length. Monotonous stack.

SAM:

  Similarly, considering the form of the prefix of the SAM: two strings starting from the root longest overlapping part is $ lcp $. The number of $ lcp $ or consideration. For common portion starting from the root, can maintain a $ g [x] $ denotes the total length of the root to $ X $ path. Enumeration first branching point $ X $, $ X $ diverges from maintenance $ f [x] $ $ X $ starts from a terminating node (may jump up from $ N $ point Last $ $ father mark) number of paths. \ Sum C_ {f [to] - when $ DP $ combined, to $ points that can not contribute so $ ans- = g [x] * (C _ {\ sum f [to]} ^ {2} from the same $ } ^ 2) $.

Generation curse:

SAM:

  Intrinsic to a different number of sub-strings of the string, the construction can be obtained SAM $ dp $. After adding modifications, based on the original is not good to directly modify the $ dp $ value, so consider a complete build a string subdivisions statistical contribution to SAM. Because it is the sequential addition of character and Statistics, the answer is actually a moment of total string in the first few answers, then the substring can generate contributions, will appear before the end point of time, that is the appropriate minimum $ endpos $ position before the point in time (there is a can, it is the smallest $ firstpos $). Built by $ ParentTree $ $ firstpos $ statistical answer.

Tasting the General Assembly:

SAM:

  Summary meaning of the questions: For point-to-$ (a, b) $, if the suffix string $ S $ $ a, b $ longest common prefix $ lcp $, then he is $ ans1 [0 \ to lcp] $ contribute $ 1 $ is for $ ans2 [0 \ to lcp] $ updated maximum. Consider building SAM, on SAM, two suffixes $ lcp $ reflected in its public path length from the root of the start of the match, and by several long path a little different, so it is not easy to calculate the $ lcp $ contribution. Let us consider the meaning of ParentTree, on the PT jump from one point to find its father represents the suffix of a string (a string that is in line with point $ endpos $ string), then the two strings $ lca $ nodes on actual PT on two strings represent common suffix. We build backward SAM, $ lca $ is $ lcp $ a. Backward endpos of $ $ string is the original starting point, that if the range is $ len $ $ [l, r] $, so to say, any of its endpos $ a $ as the starting point, will be backward (direction of the original sequence ) extending from the same [l, r] the length of the string, which string has [l, r] common prefix. As the title statistical point of statistics rather than the number of sub-strings, then we point endpos optional PT from the two starting points, which can later match the $ [l, r] $ length, can be thought $ ans1 [l \ to r] $ make $ 1 $ contribution. Such contributions out of range add suffixes and do not need to answer, because we have chosen to $ endpos $ two points, although it only had $ [l, r] $ contributions, but the PT its parent node collection it also contains a collection of $ endpos $ and $ len <l $, set it on the PT contained in his son's collection, and $ len> r $, so that any two starts from the starting point, all extending rearwardly length can be matched to the statistics can be. Seeking the maximum value is similar, $ endpos $ maintenance on the maximum PT node, the second largest, smallest, second smallest can. If the last for a maximum of $ max $ suffix, then, here you can not make the interval to take $ max $, as long as the count at $ maxlen $ answers just fine.

TO:

  用SA解决$lcp$就比较简便了,我们求出$height$后,按$rank$排序,用单调栈求出一个点$x$的控制区间(以它的$height$为最小的区间)。对于那个区间,如果选了$x-1$,那么再选$[x,ri[x]]$都是$height[x]$为$lcp$;或者如果选了$x$,那么再选$[le[i],x-1]$都是$height[x]$为$lcp$。这样方案数可以直接算得,点对最大权值就可以ST表区间查询,并且只用维护美味度最大、最小值。

Guess you like

Origin www.cnblogs.com/Duan-Yue/p/12093744.html