#P6656. 【模板】Runs

【模板】Runs

Description

Define a run in a string SS of length S|S| as a periodic substring that cannot be extended on either side, and whose period appears at least twice completely.

More precisely, a run is a triple (i,j,p)(i, j, p) such that pp is the minimal period of S[i..j]S[i..j], ji+12pj - i + 1 \ge 2p, and the following two conditions hold:

  • Either i=1i = 1, or S[i1]S[i1+p]S[i - 1] \ne S[i - 1 + p].
  • Either j=nj = n, or S[j+1]S[j+1p]S[j + 1] \ne S[j + 1 - p].

Given a string SS, find all runs in it.

Input Format

One line containing a string SS, guaranteed to consist only of lowercase letters.

Output Format

The first line contains an integer mm, the number of runs.

The next mm lines each contain three integers describing a run:

  • The position of the first character of this run.
  • The position of the last character of this run.
  • The length of the minimal period of this run.

You should sort all runs by the position of the first character as the primary key, and the position of the last character as the secondary key.

aababaababb
7
1 2 1
1 10 5
2 6 2
4 9 3
6 7 1
7 10 2
10 11 1

Hint

For 60%60\% of the testdata, S2×105|S| \le 2 \times 10^5.

For 100%100\% of the testdata, S106|S| \le 10^6.

Translated by ChatGPT 5