PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000004. Biến đổi mảng thành thứ hạng (Rank Transform of an Array)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Biến đổi mảng thành thứ hạng (Rank Transform of an Array)
Rank Transform of an Array
Source: LeetCode Version: Phuoc Hung OJ Extended
Problem Statement
Given an integer array, replace every element with its rank among its distinct values. The smallest value has rank ; equal values share a rank; ranks increase consecutively; the original element order is preserved.
Input
The first line contains . If , the next line contains integers .
Output
Print the ranks on one line separated by spaces. For , print no values.
Subtasks
- Subtask 1 (20 points): ; (when ).
- Subtask 2 (30 points): ; (when ).
- Subtask 3 (50 points): ; (when ).
Examples
Input
5
-4 10 -4 7 0
Output
1 4 1 3 2
Explanation
The sorted unique values are . Both occurrences of receive rank .