# codeforce之 Bear and Colors

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 ti.

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.

Input

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

The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ n) where ti is the color of the i-th ball.

Output

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

N^2级别，在循环的同时进行更新从当前地点开始每个颜色出现的次数。然后和前一个进行比较是否更新了最大值

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<iomanip>
#include<string.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<cstdio>
#include<string>

using namespace std;
int num[5002][5002] = { 0 };
int ans[5002] = { 0 };
int color[5002];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> color[i];
}
for (int i = 0; i < n; ++i) {
int max = 0;
int temp = color[i] - 1;
for (int j = i; j < n; ++j){
num[i][color[j] - 1]++;
if (num[i][color[j] - 1] > max) {
max = num[i][color[j] - 1];
temp = color[j] - 1;
}
else if (num[i][color[j] - 1] == max)
{
if (color[j] - 1< temp) {
temp = color[j] - 1;
}
}
ans[temp]++;
}
}
for (int i = 0; i < n; ++i){
cout << ans[i] << " ";
}
//system("pause");
}

• 本文已收录于以下专栏：

## Codeforces 673C Bear and Colors【暴力枚举】

C. Bear and Colors time limit per test 2 seconds memory limit per test 256 megabytes inpu...
• mengxiang000000
• 2017年02月12日 17:17
• 592

## Codeforces 907A Masha and Bears

A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb ...
• finalcsdn
• 2017年12月24日 17:17
• 162

## codeforce之Bear and Two Paths

• luckyu1
• 2016年05月31日 11:46
• 153

## codeforce（找规律的简单题）

D. Prizes, Prizes, more Prizes time limit per test 2 seconds memory limit per test 256 megabytes...
• 2015年04月22日 21:00
• 952

## CodeForces 673C Bear and Colors

• qq_21057881
• 2016年05月10日 19:40
• 1464

## Codeforce - 573B - Bear and Blocks

B. Bear and Blocks time limit per test1 second memory limit per test256 megabytes inputstandard i...
• qq_36551426
• 2017年02月26日 10:05
• 79

## 【codeforces454div2】A. Masha and Bears

A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb ...
• c_circle
• 2017年12月24日 17:33
• 86

## Codeforces673C Bear and Colors(枚举区间)

C. Bear and Colors time limit per test 2 seconds memory limit per test 256 megabytes input sta...
• KeyboardMagician
• 2016年07月27日 20:50
• 409

## markdown 最新语法

• ws1352864983
• 2016年03月05日 01:06
• 444

## CodeForces 673C - Bear and Colors(模拟)

C. Bear and Colors time limit per test2 seconds memory limit per test256 megabytes inputstandard ...
• Snakeflute
• 2016年12月07日 17:59
• 249

举报原因： 您举报文章：codeforce之 Bear and Colors 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)