QOJ.ac

QOJ

시간 제한: 2 s 메모리 제한: 1024 MB

#23972. 距離

통계

有 $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.