QOJ.ac

QOJ

Süre Sınırı: 2 s Bellek Sınırı: 1024 MB

#23972. 距離

İstatistikler

有 $N$ 個球排成 $1$ 列。從左往右依次稱為球 $1, 2, \dots, N$。球 $i$ 被塗上顏色 $C_i$。

對於每個 $i = 1, 2, \dots, N$,求以下值:

  • 與球 $i$ 顏色相同的所有球到球 $i$ 的距離之和。其中,球 $i$ 與球 $j$ 之間的距離定義為 $|i - j|$。

限制條件

  • $1 \le N \le 100$。
  • $1 \le C_i \le 100$ ($1 \le i \le N$)。
  • 輸入的值皆為整數。

輸入格式

輸入以下列格式給出:

N
C_1 C_2 ... C_N

輸出格式

輸出共 $N$ 行。在第 $i$ 行 ($1 \le i \le N$) 輸出與球 $i$ 顏色相同的所有球到球 $i$ 的距離之和。

除答案外請勿輸出任何內容。(亦請勿輸出提示輸入的文字等。)

範例

範例輸入 1

4
1 2 1 1

範例輸出 1

5
0
3
4

範例說明 1

球 $1$ 被塗上顏色 $1$,球 $2$ 被塗上顏色 $2$,球 $3$ 被塗上顏色 $1$,球 $4$ 被塗上顏色 $1$。

  • 對於 $i = 1$,與球 $1$ 顏色相同的球是球 $1, 3, 4$,它們與球 $1$ 的距離分別為 $0, 2, 3$,因此輸出 $0 + 2 + 3 = 5$。
  • 對於 $i = 2$,與球 $2$ 顏色相同的球只有球 $2$,它與球 $2$ 的距離為 $0$,因此輸出 $0$。
  • 對於 $i = 3$,與球 $3$ 顏色相同的球是球 $1, 3, 4$,它們與球 $3$ 的距離分別為 $2, 0, 1$,因此輸出 $2 + 0 + 1 = 3$。
  • 對於 $i = 4$,與球 $4$ 顏色相同的球是球 $1, 3, 4$,它們與球 $4$ 的距離分別為 $3, 1, 0$,因此輸出 $3 + 1 + 0 = 4$。

範例輸入 2

1
100

範例輸出 2

0

範例說明 2

球 $1$ 被塗上顏色 $100$。

  • 對於 $i = 1$,與球 $1$ 顏色相同的球只有球 $1$,它與球 $1$ 的距離為 $0$,因此輸出 $0$。

範例輸入 3

8
1 3 9 7 3 3 7 9

範例輸出 3

0
7
5
3
4
5
3
5

範例輸入 4

10
1 1 1 1 1 1 1 1 1 1

範例輸出 4

45
37
31
27
25
25
27
31
37
45

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.