Suffix Automata Practice Topic

Source: Internet
Author: User

Suffix automata practice topics Some of the more useful stuff:
  • (1) \ (\text{sam}\) the path from the initial state corresponds to a substring

  • (2) \ (\text{parent}\) Tree A node can represent the longest string corresponding to a prefix/suffix

  • (3) \ (len (u) \) indicates the length of the longest string that the node \ (u\) can represent

  • (4) \ (fa (U) \) indicates the node that the node \ (u\) has a suffix link to, that is, its father on the \ (\text{parent}\) tree

  • (5) A node that represents a public prefix of two suffixes is two suffixes on \ (\text{parent}\) tree \ (lca\)

  • (6) \ (r (u) \) represents the \ (\text{right}\) collection of Nodes \ (u\) ,\ (sz (u) \) represents the size of \ (r (u) \) , \ (r (U) \subset r (FA (U)), sz (U) < sz (FA (U) )

  • (7) Generalized \ (\text{sam}\) can be understood as a \ (\text{sam}\) to maintain multiple strings, each time a string is inserted after the \ (tail\) pointer is set to the initial state


Spoj 1811 longest Common Substring

Give two strings \ (S, t\), ask for the longest common substring of this \ (s, t\) ,\ (|s|, |t| \leq 2.5 \times 10^5\)

? For \ (s\) build \ (\text{sam}\) , according to (1) can put \ (t\) into \ (\text{sam}\) match, When mismatch is equivalent to continuing to start the match from a suffix of the string currently matched to, equivalent to jumping on \ (\text{sam}\) \ (FA (U) \) . It can be proved that this must match to the longest common substring.


Spoj 1812 Longest Common Substring II

Give \ (n\) A string, the longest common substring of this \ (n\) string,\ (1 \leq n \leq, |s| \leq 10^5\)

? Similar to the previous question, or take out a string build \ (\text{sam}\), you can find out how many strings each node is matched to, then the answer is \ (\max (len (u)) \),\ (u\) is the node to which the \ (n-1\) string is matched. Consider each time the match to a node, according to (6), its ancestor represents the string will also be matched to, so each string match after the update of its ancestor's match number, violence upward jump can.

? Another approach, consider the number of strings only \ (10\) , you can build a generalized \ (\text{sam}\) to put all the strings in, with binary maintenance \ (R (u) \) contains the suffix from a string, When a node contains suffixes from all strings, it can contribute to the answer. When \ (n\) is larger, it can be maintained with \ (\text{bitset}\) or line segment tree merging.


Spoj 7258 lexicographical Substring Search

Give a string \ (s\), and \ (q\) a query, each query \ (s\) the small sub-string ( k\) , the repeating substring is counted only once, \ (|s| \leq 9 \times 10^4, Q \leq 500\)

? You can not consider the \ (\text{parent}\) tree, only consider (1), calculate the number of paths each node can go down. Because of the requirement is the dictionary order (k\) Small, each time two separate from this node should go to the transfer side of the character is what, go down. The complexity of doing this is \ (O (|s|q) \), because \ (q\) is small enough to pass this problem.

? actually consider \ (\text{parent}\) can further optimize the complexity of the algorithm, consider the original \ (\text{parent}\) tree node represented by the multiple strings are the longest string of a suffix, is a structure similar to the prefix tree, which does not apply to the graceful nature of some dictionary sequences. It may be possible to insert the string reverse order into \ (\text{sam}\) , so that each point can represent a number of strings are the longest string prefix, these strings from long to short in the dictionary sequence must be orderly. Extends to the entire tree, depending on \ (MN (U) = Len (fa (U)) + 1\) , each point represents a string that is larger than the dictionary of the string represented by its ancestor. So we can calculate how many strings each subtrees tree represents, in the (\text{dfn}\) order The answer can be two points, the complexity is \ (O (QLOGN) \).


"tjoi2015" string theory

Give a string \ (s\) , according to the topic request to find out the same sub-string count one or more k\ ( |s| \leq 5 \times 10^5\)

? The first question is completely equivalent to the previous one, considering the second question, the number of occurrences of a substring in \ (s\) is its corresponding \ (\text{parent}\) tree node \ (\text{right}\) collection size , that is, (sz (u) \) , only need to each path to the weighted value of \ (sz (u) \) statistics can be.


Codechef January Challenge 2018-killjee and k-th letter

Give a string \ (s\), will \ (s\) all sub-strings in accordance with the dictionary sequence to form a new string,\ (q\) inquiry, each time asked to ask the new string of the first \ (k\) A character is what, force online. \ (|s|, q \leq 2 \times 10^5\)

? Considering the previous question to the \ (\text{parent}\) approach, the string represented by each node in the reverse order is ordered in the \ (\text{dfn}\) order, so only the number of strings represented by each node is required, and then the The \ (\text{dfn}\) sequence is divided to find the answer on which node represents the substring. Consider a substring that represents the string length from \ ([Len (FA (U)) +1,len (U)]\) , which can be directly calculated for the number of bits (k\) corresponding to the suffix from node \ (u\) . Find the character of the position on the original string

Codeforces 873 F. Forbidden Indices

There is a string \ (s\), where\ (s\) is illegal, ask for all substrings that do not end with an illegal position ( a\) ,\ (\sum|a|\times tot (a) \) value, where \ (tot (a) \) indicates the number of occurrences of \ (a\) in \ (s\) . \ (|s| \leq 2 \times 10^5\)

? The total number of strings represented by a node on the \ (\text{parent}\) tree is \ ((Len (U)-len (FA (U))) \times sz (u) \) , maintaining each string without an illegal location \ (\text {right}\) sum directly after the collection size


"ahoi2013" differences

Given a string \ (s\) , for all its suffixes \ (t_i, t_j\) , ask \ (\sum len (t_i) +len (T_j)-2len (LCP (t_i, t_j)) \) the value, \ (|s| \leq 5 \times 10^5\)

? After considering inserting the sequence into the \ (\text{parent}\) tree, the \ ( \text{lcp}\) of the two suffix nodes is their \ (\text{lca}\) , then they can be tree-shaped \ (\text{dp}\) is obtained at each node as \ (\text{lca}\) (\sum len (t_i) +len (T_j)-2len (U) \) , Finally, summing all the nodes is the answer.


"noi2015" Wine Tasting Conference

Given a string \ (s\) and a sequence \ (a\) , for all \ (i\) , find the number of scenarios for the \ ( LCP (x, y) \geq i\) and the largest \ (a_x \times a_y\) \ (|s| \leq 3 \times 10^5|a_i| \leq 10^9\)

? In essence, as in the previous procedure, consider the first question only ask for each node \ (u\) , in its subtree select two nodes \ (\text{lca}\) to \ (u\) The number of scenarios, the second question is slightly complex, Because the weights can be positively negative, it is necessary to maintain the maximum and minimum values for the classification discussion \ (\text{dp}\) to facilitate the statistical answer when the merging is multiplied.


"bzoj3473" string (double experience =3277)

A \ (n\) string is given to ask how many substrings are substrings of at least \ (k\) strings,\ (\sum|s| \leq 10^5, 1\leq k \leq n\)

? Establish a generalized \ (\text{sam}\) that maintains the \ ( \text{right}\) of the nodes on the \ (\text{parent}\) tree Each time a string is inserted. The collection already has a suffix from this string, so that each new insertion node needs to update this information to the ancestor, and the total complexity of inserting all the strings is \ (O (|s|\sqrt|s|), based on the mean inequality analysis. \).

? Consider that you can directly use the line segment tree to maintain each node's \ (\text{right}?\) collection of the string suffix, all built up after the update of the ancestors of the answer, the total complexity of (O (|s|log|s|)? \).


The "zjoi2015" of the Gods

There is a tree \ (n\) node, each node has a character, now each simple path as a string, to find the number of essential different substrings,\ (n \leq 10^5\) Tree leaf node number \ (\leq 10\)

? If a simple path is contained by another simple path, then the string represented by it can be considered as a substring of another string, so we only need to consider the simple path that is not contained by any string, the number of which is obviously the square of the number of leaf nodes. So violence inserts these strings into generalized \ (\text{sam}\) to count the number of different substrings.


"sdoi2016" Spawn Spell

There is an empty string at the beginning, there are \ (n\) operations, each operation at the end of the string with a character, for each operation at the end of the string of the number of different substrings \ (n \leq 10^5\)

? \ (\text{sam}\) is constructed on-line, each time the insertion node \ (p\) to maintain the \ (len\) changes in the node's contribution to the answer


"bzoj2555"substring

Inserts a string after the current string
How many times does the query string \ (s\) appear in the current string? You must support these operations online (as a continuous substring).

? A problem that is insane, since the online insertion of the string to \ (s\) to maintain each point of the \ (sz (u) \) , so to dynamically support the \ (\text{parent}\) tree plus edge, Maintain subtree size can be added to the chain, with \ (lct\) to maintain the


Codeforces 666 E. Forensic examination

Give you a string and a lot of inquiry string, each time asked to find a section of the string in a continuous query string of the number of occurrences and number of the query string \ (1 \leq |s|, q \leq 5 \times 10^5\)

? For all strings of a generalized \ (\text{sam}\) , each query multiplies to find the left point in the \ (\text{parent}\) tree corresponding to the node, using a line segment tree to maintain each node's \ (\text{right }\) The number of occurrences of each query string in the collection, interval lookup \ (\max\)


"tjoi/heoi2016" string

? Transmission Door


"noi2018" your name (non-positive solution)

? Transmission Door


Four methods of "bjwc2018"border (to be pits)

?

Suffix Automata Practice Topic

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.