#P4248. [AHOI2013] 差异

    ID: 3176 远端评测题 2000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2013各省省选安徽后缀自动机,SAM后缀数组,SA后缀树

[AHOI2013] 差异

Description

Given a string SS of length nn, let TiT_i denote the suffix starting from its ii-th character. Compute

$$\displaystyle \sum_{1\leqslant i<j\leqslant n}\operatorname{len}(T_i)+\operatorname{len}(T_j)-2\times\operatorname{lcp}(T_i,T_j)$$

where len(a)\text{len}(a) denotes the length of string aa, and lcp(a,b)\text{lcp}(a,b) denotes the longest common prefix of strings aa and bb.

Input Format

One line, a string SS.

Output Format

One line, an integer representing the required value.

cacao
54

Hint

Constraints

  • For 100%100\% of the testdata, it is guaranteed that 2n5000002\le n\le 500000, and all characters in SS are lowercase letters.

Translated by ChatGPT 5