Written before
Border Theory,which was not well-known enough,should have been publicized together with KMP or similar algorithms.But nowadays lots of people don't know such a theory exist,making them unable to solve several tasks easily or even can't get a fast solution.So it's time to complete the blog as what I will do on this.
Ordinary Border Theory
Conclution
For a string $$$S$$$, There are a squence of strings:
it's garenteed that there exist a way to divide the sequence into $$$\operatorname{O}(\log |S|)$$$ continuous subsequence that each subsequence forms an arithmetic sequence.
Proof
First of all,we found that if there's a string $$$T$$$ as a border of $$$S$$$ and $$$2|T| \ge |S|$$$, Then the sequence of where $$$T$$$ appears in $$$S$$$ forms an arthmetic sequence.
Second,We found that all lengths of border $$$T$$$ that $$$2|T| \ge |S|$$$ will form an arthmetic sequence:
So there's a way that if $$$p \lt q,p,q \text{are the length of borders}$$$ not in the same continuous sequence, $$$2p \lt q$$$ exist,So the conclution is right.
Tasks
Task $$$1$$$:given at most $$$5$$$ cases in a test case,each cases gives a string $$$S(1 \le |S| \le 5 \times 10 ^ 5)$$$ and an integer $$$w(1 \le w \le 10 ^ {18})$$$, when we have a string $$$T$$$ we can make the new string by $$$|T| + |S|$$$ or if a suffix $$$A$$$ in $$$T$$$ is also the prefix of $$$S$$$, $$$T - A + S$$$ can be formed as there's a string of length $$$|T| - |A| + |S|$$$.Find the number of distinct length of strings in $$$[1,w]$$$ can be formed.



