链接:
https://ac.nowcoder.com/acm/contest/33192/I
来源:牛客网
Grammy has a string SSS of length nnn containing only lowercase letters.
For a string
sss, if we record the first occurrence of each type of character in order as
t1,t2,t3,…,tkt_1, t_2, t_3, \dots, t_kt1,t2,t3,…,tk, then the minimal representation of
sss can be obtained by replacing all occurrence of
t1t_1t1 in
sss by the first character of the character set (
a), replacing all occurrence of
t2t_2t2 in
sss by the second character of the character set (
b), and so on.
For example, when the character set is lowercase, the minimal representation of “edcca” is “abccd”, and “xy” and “zt” are essentially the same in terms of minimal representation.
Your task is sorting all suffixes of
SSS with a special regularity.
For two suffixes
S[i:]S[i:]S[i:] and
S[j:]S[j:]S[j:], if the minimal representation of
S[i:]S[i:]S[i:] is less than
the minimal representation of
S[j:]S[j:]S[j:] in the lexicographic order, then
S[i:]S[i:]S[i:] is less than
S[j:]S[j:]S[j:] in the special regularity.
Please output the result array
sa[i]sa[i]sa[i] of the suffix sort with the special regularity. The
iii-th element of
sa[i]sa[i]sa[i] is the position of the first character in the i-th smallest suffix of
SSS with the special regularity.