PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000283. Tổng khoảng cách giữa các phần tử giống nhau (Intervals Between Identical Elements)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tổng khoảng cách giữa các phần tử giống nhau (Intervals Between Identical Elements)
Intervals Between Identical Elements
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Given an integer sequence , calculate for every index . If no other index carries the same value, . Output the results in original index order.
Input
First line: integer . Second line: exactly integers .
Output
Print integers on one line, separated by spaces.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; ; all elements are pairwise distinct.
- Subtask 3 (50 points): ; .
Example 1
Input
7
2 1 3 1 2 3 3
Output
4 2 7 2 4 4 5
Explanation
Value 2 occurs at positions 1, 5, distance 4; value 1 at 2, 4, distance 2; value 3 at 3, 6, 7, giving 7, 4, 5 respectively.
Example 2
Input
4
10 5 10 10
Output
5 0 3 4
Explanation
The positions carrying 10 are 1, 3 and 4, giving 5, 3, 4. Value 5 occurs once.