QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#21648. Runs

统计

Source: Libre OJ 173

定义一个字符串 $|S|$ 里的一个 run,指其内部一段两侧都不能扩展的周期子串,且周期至少完整出现两次。

严格地说,一个 run 是一个 三元组 $(i,j,p)$,满足 $p$ 是 $S[i..j]$ 的最小周期,$j-i+1 \ge 2p$,且满足如下两个条件:

  • 要么 $i=1$,要么 $S[i-1]\ne S[i-1+p]$;
  • 要么 $j=n$,要么 $S[j+1] \ne S[j+1-p]$。

给定字符串 $S$,求他的所有 runs。

Input

一行一个字符串 $S$,保证其只由小写字母构成。

Output

第一行一个整数 $m$,表示 runs 的数量。

接下来 $m$ 行,每行三个整数 $i,j,p$ 描述一个 runs。

你应该以第一个字符的位置为第一关键词,最后一个字符的位置为第二关键词对所有的 runs 进行排序。

Example

Input

aababaababb

Output

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

Scoring

对于 $60\%$ 的数据,$|S| \le 2 \times 10^5$。

对于 $100\%$ 的数据,$|S| \le 10^6$。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.