C. 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
4
1 2 1 2
output
7 3 0 0 
input
3
1 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.

题意:找出每个区间的重数,将重数的次数输出;

思路:暴力找复杂度o(n*n)

#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define mod 1000000007
#define inf 999999999
//#pragma comment(linker, "/STACK:102400000,102400000")
int scan()
{
int res = , ch ;
while( !( ( ch = getchar() ) >= '' && ch <= '' ) )
{
if( ch == EOF ) return << ;
}
res = ch - '' ;
while( ( ch = getchar() ) >= '' && ch <= '' )
res = res * + ( ch - '' ) ;
return res ;
}
int a[];
int flag[];
int ans[];
int main()
{
int x,y,z,i,t;
scanf("%d",&x);
for(i=;i<=x;i++)
scanf("%d",&a[i]);
for(i=;i<=x;i++)
{
memset(flag,,sizeof(flag));
int maxx=,ji;
for(t=i;t<=x;t++)
{
//cout<<maxx<<" "<<ji<<" "<<a[t]<<endl;
flag[a[t]]++;
if(flag[a[t]]>maxx)
{
maxx=flag[a[t]];
ji=a[t];
ans[ji]++;
}
else if(flag[a[t]]==maxx&&ji>a[t])
{
ji=a[t];
ans[ji]++;
}
else
ans[ji]++;
}
}
for(i=;i<=x;i++)
printf("%d ",ans[i]);
return ;
}

最新文章

  1. gulp教程之gulp-minify-css
  2. WPF点补间、拟合回归直线
  3. ruby -- 基础学习(四)TimeDate处理
  4. java build path-&gt;source folder分析
  5. A-frame_02
  6. fcitx中文输入法
  7. 让IE6兼容position:fixed
  8. linux下安装svn(基于编码的方式)
  9. InstallShield limited edition 生成单个 setup.exe 安装文件
  10. mysql 修复表和优化表
  11. Android内存泄漏简介
  12. 轻松理解JavaScript之AJAX
  13. dubbo服务的发布和调用
  14. ES6的 let const 以及块级作用域
  15. Nginx模块
  16. 网络互联技术(2)——前篇—【转载】电脑结构和CPU、内存、硬盘三者之间的关系
  17. CF 833B
  18. 计算概论(A)/基础编程练习1(8题)/1:大象喝水
  19. myeclipse从svn导入文件报错:
  20. 什么是BFC(Block Formatting Context)

热门文章

  1. [py]戏说python面向对象细节
  2. INT_MAX和INT_MIN注意事项
  3. matplotlib--画图时保存图片空白的问题
  4. liunx anacoda 安装pyltp
  5. mongodbtemplate配置
  6. python 打印输出至文件中, &#39;wt&#39;读写文件方式,会把原文件内容清空
  7. Python tricks(7) -- new-style class的__slots__属性
  8. 浅谈为什么一个java源文件中只能有一个public类?
  9. linux常用命令:Linux 文件属性详解
  10. Linux服务器配置---配置telnet