#GSP1. Dictionary order
Dictionary order
English Version:
We have n characters in alphabetical table and n circle permutations. They (permutation) need to be ascendingly sorted in dictionary order. If same dictionary orders are found in 2 permutations, higher priority belongs to one having lower starting character's index (in input given).Input:
+) First line contains n (1 <= n <= 5 * 104).+) n following lines: ith line is written a_i (1 <= a_i <= 231), ith character's order in alphabetical table.
Output:
Write n lines with n indexes after sorting, respectively.Example:
Data:
5
2
1
1
2
4
Result:
2
3
1
4
5
5
2
1
1
2
4
Result:
2
3
1
4
5
Vietnamese Version:
Cho n kí tự trong bảng kí tự. Xét n hoán vị vòng quanh. Sắp xếp chúng theo thứ tự từ điển tăng dần. Nếu 2 hoán vị có cùng thứ tự từ điển thì ưu tiên hoán vị có chỉ số của kí tự bắt đầu nhỏ hơn xếp trước.Input:
+) Dòng đầu ghi số n (1 <= n <= 5 * 104).+) N dòng sau: dòng thứ i ghi a_i (1 <= a_i <= 231) là thứ tự của kí tự thứ i trong bảng chữ cái.
Output:
ghi ra n dòng là n chỉ số tương ứng sau khi sắp xếp.Ví dụ
Dữ liệu:
5
2
1
1
2
4
Kết qủa:
2
3
1
4
5