#P2408. 不同子串个数

    ID: 1410 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>字符串动态规划,dp线性结构后缀自动机,SAM

不同子串个数

Description

Given a string of length nn, find the number of distinct substrings.

We define two substrings to be different if and only if either their lengths are different, or their lengths are the same but there exists at least one position where they differ.

A substring is defined as a contiguous segment of characters in the original string.

Input Format

The first line contains an integer nn.

The second line contains nn characters representing the given string.

Output Format

Output a single integer in one line, representing the number of distinct substrings.

5
aabaa
11
3
aba
5

Hint

Please use a 64-bit integer for the output.

Constraints

  • For 30% of the testdata, n1000n \le 1000.
  • For 100% of the testdata, 1n1051 \leq n \le 10^5, and the string contains only lowercase English letters.

Translated by ChatGPT 5