8574: Suffix Sort

内存限制:1024 MB 时间限制:4 S
题面:传统 评测方式:文本比较 上传者:
提交:2 通过:0

题目描述

链接: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.

输入格式


The first line contains one integers nnn (1≤n≤2000001 \le n \le 200\,0001n200000).
The next line contains a string SSS of length nnn. It is guaranteed that SSS only consists of lowercase English alphabets.

输出格式


Output nnn integers in a single line, representing the answer.

输入样例 复制

6
aadead

输出样例 复制

6 1 5 4 3 2

分类标签