Suffix Sort
시간 제한4초메모리 제한1024 MB
소문자 문자열의 모든 접미사를 최소 표현 R(P)의 사전순으로 정렬하고 각 접미사의 시작 인덱스 배열을 출력합니다.
입력과 출력
Grammy has a string of length that consists of lowercase English letters.
For a string , reading it left to right, write down the letters that never occurred before as . For example, if "sesame", we write down 's', 'e', 'a', 'm'. The minimal representation can be obtained by replacing every occurrence of in by the first character of the character set ("a"), replacing every occurrence of in by the second character of the character set ("b"), and so on.
For example, when the character set is lowercase English letters, the minimal representation of "sesame" is "abacdb", the minimal representation of "edcca" is "abccd", and minimal representations "xy" and "zt" are both "ab".
Your task is to sort all suffixes of by their minimal representation. Formally, denote suffix as . For two suffixes and , if is less than in lexicographical order, then has to occur before in the desired order.
Please output the result as an array of indices : the -th element of must be the position of the first character in the -th smallest suffix of in the desired order. Formally, the array must satisfy