CF643A.Bear and Colors

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Bear Limak has n colored balls, arranged in one long row. Balls are numbered 1 through n, from left to right. There are n possible colors, also numbered 1 through n. The i-th ball has color t__i.

For a fixed interval (set of consecutive elements) of balls we can define a dominant color. It's a color occurring the biggest number of times in the interval. In case of a tie between some colors, the one with the smallest number (index) is chosen as dominant.

There are non-empty intervals in total. For each color, your task is to count the number of intervals in which this color is dominant.

熊 Limak 有 n 个彩色小球,排成一长排。小球从左到右编号为 1 至 n。共有 n 种可能的颜色,也编号为 1 至 n。第 i 个小球的颜色为 t__i。

对于一个固定的区间(即一组连续的小球),我们可以定义其“主导颜色”:即在该区间中出现次数最多的颜色。若存在多种颜色出现次数相同(即平局),则选择编号(索引)最小的那种颜色作为主导颜色。

总共有 个非空区间。对每种颜色,你的任务是统计以该颜色为主导颜色的区间个数。

输入格式

The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — the number of balls.

The second line contains n integers _t_1, _t_2, ..., t__n (1 ≤ t__i ≤ n) where t__i is the color of the i-th ball.

输入的第一行包含一个整数 nn(1≤n≤50001 \leq n \leq 5000)—— 表示球的数量。

第二行包含 nn 个整数 t1,t2,…,tnt_1, t_2, \dots, t_n(1≤ti≤n1 \leq t_i \leq n),其中 tit_i 表示第 ii 个球的颜色。

输出格式

Print n integers. The i-th of them should be equal to the number of intervals where i is a dominant color.

输出 nn 个整数。其中第 ii 个整数应等于满足“ii 是该区间中主导颜色”的区间个数。

输入输出样例

  • 输入#1

    4
    1 2 1 2

    输出#1

    7 3 0 0
  • 输入#2

    3
    1 1 1

    输出#2

    6 0 0

说明/提示

In the first sample, color 2 is dominant in three intervals:

  • An interval [2, 2] contains one ball. This ball's color is 2 so it's clearly a dominant color.
  • An interval [4, 4] contains one ball, with color 2 again.
  • An interval [2, 4] contains two balls of color 2 and one ball of color 1.

There are 7 more intervals and color 1 is dominant in all of them.

在第一个样例中,颜色 2 在三个区间中占主导地位:

  • 区间 [2, 2] 包含一个球,该球的颜色为 2,因此颜色 2 显然是主导颜色。
  • 区间 [4, 4] 包含一个球,其颜色同样为 2。
  • 区间 [2, 4] 包含两个颜色为 2 的球和一个颜色为 1 的球。

其余还有 7 个区间,颜色 1 在所有这些区间中均占主导地位。

输入解题思路,AI测评打分。不知道怎么写?

首页