codeforces 673C

来源:互联网 发布:dna怎么入公安数据库 编辑:程序博客网 时间:2024/06/16 15:23

Bear and Colors
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Examples
input
41 2 1 2
output
7 3 0 0 
input
31 1 1
output
6 0 0 
Note

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.


已知一串数字,每种数字代表一种颜色,如果一个区间[i,j]中, ai颜色出现次数最多或者有和ai出现次数一样多的颜色但是颜色编号都比ai大,那么ai就是这个区间的领导颜色,统计各种颜色领导的区间数量。

模拟一下就好了

#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<string>#include<vector>#include<stack>#include<set>#include<map>#include<queue>#include<algorithm>using namespace std;int ball[5005],coun[5005],col[5005];int main(){int i,j;int cal=0;int n;scanf("%d",&n);for(i=1;i<=n;i++){scanf("%d",&ball[i]);}int len;int tmp;int max=0;for(i=1;i<=n;i++){max=0;col[ball[i]]++;coun[ball[i]]++;if(max<coun[ball[i]]){max=coun[ball[i]];tmp=ball[i];}for(j=i+1;j<=n;j++){coun[ball[j]]++;if(max<coun[ball[j]]){max=coun[ball[j]];tmp=ball[j];}else if(max==coun[ball[j]]){if(tmp>ball[j]){tmp=ball[j];}}col[tmp]++;}memset(coun,0,sizeof(coun));}for(i=1;i<=n;i++){printf("%d",col[i]);if(i!=n)printf(" ");}printf("\n");    return 0;}




0 0
原创粉丝点击