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.

模拟每个区间,通过if(cnt[a[j]]>cnt[a[best]]||(cnt[a[j]] == cnt[a[best]]&&a[j]<a[best]))  best = j来转移

 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn = ;
int a[maxn],cnt[maxn],ans[maxn];
void solve(){
int n;
scanf("%d",&n);
for(int i = ; i<=n; i++) scanf("%d",&a[i]);
for(int i = ; i<=n; i++){
// ans[a[i]]++;
int best = i;
memset(cnt,,sizeof(cnt));
// for(int j = i; j<=n; j++) cnt[a[j]] = 0;
for(int j = i; j<=n; j++)
{
cnt[a[j]]++;
if(cnt[a[j]]>cnt[a[best]]||(cnt[a[j]] == cnt[a[best]]&&a[j]<a[best])) best = j;
ans[a[best]]++;
}
}
for(int i = ; i<n; i++)
{
printf("%d ",ans[i]);
}
printf("%d",ans[n]); }
int main()
{
solve();
return ;
}

C. Bear and Colors的更多相关文章

  1. codeforces 351 div2 C. Bear and Colors 暴力

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

  2. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C. Bear and Colors 暴力

    C. Bear and Colors 题目连接: http://www.codeforces.com/contest/673/problem/C Description Bear Limak has ...

  3. codeforces 673C C. Bear and Colors(暴力)

    题目链接: C. Bear and Colors time limit per test 2 seconds   memory limit per test 256 megabytes input s ...

  4. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C - Bear and Colors

    题目链接: http://codeforces.com/contest/673/problem/C 题解: 枚举所有的区间,维护一下每种颜色出现的次数,记录一下出现最多且最小的就可以了. 暴力n*n. ...

  5. [Codeforces673C]Bear and Colors(枚举,暴力)

    题目链接:http://codeforces.com/contest/673/problem/C 题意:给一串数,不同大小的区间内出现次数最多的那个数在计数的时候会+1,问所有区间都这样计一次数,所有 ...

  6. C. Bear and Colors 区间枚举的技巧

    http://codeforces.com/problemset/problem/673/C 先说一个枚举区间的技巧,枚举前缀,不要枚举后缀. 就是下面这个代码是不好的 ; i <= n; ++ ...

  7. 【Henu ACM Round#16 B】 Bear and Colors

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] O(n^2)枚举每一个区间. 然后维护这个区间里面的"统治数字"是什么. 对于每个区间cnt[统治数字]++; ...

  8. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C (用map 超时)

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

  9. Sort Colors

    Given an array with n objects colored red, white or blue, sort them so that objects of the same colo ...

随机推荐

  1. CentOS + EPEL YUM源地址

    [bizosv] name=bizsov-centos-$releasever - centos baseurl=http://yikat:yikat@download.bizsov.com/ gpg ...

  2. requirejs 一个拆分js项目的类库

    http://www.requirejs.cn/ http://requirejs.org/docs/start.html

  3. GitHub这么火,程序员你不学学吗? 超简单入门教程 【转载】

    本GitHub教程旨在能够帮助大家快速入门学习使用GitHub. 本文章由做全栈攻城狮-写代码也要读书,爱全栈,更爱生活.原创.如有转载,请注明出处. GitHub是什么? GitHub首先是个分布式 ...

  4. listview前几个item的图片怎么是空白的、listview更新了ui不起作用、在handler里更新了UI不起作用

    不是不起作用,不信你可以在更新ui代码附近加输出的log,说明程序是跑到那里了.但是未达到我们的想要的效果. 我们知道在listview里更新UI,listview的适配器Adapter里有个getV ...

  5. js css优化-- 合并和压缩

    在项目框架中,首先要引用很多css和js文件,80%的用户响应时间都是浪费在前端.而这些时间主要又是因为下载图片.样式表.JavaScript脚本.flash等文件造成的.减少这些资源文件的Reque ...

  6. php根据时间显示刚刚,几分钟前,今天,昨天的实现代码

    如果大家有更好的方案欢迎交流 function diffBetweenTwoDay($pastDay){ $timeC = time() - strtotime($pastDay); $dateC = ...

  7. javascript string去除两边空格

    function trim(){ return this.replace(/(^\s*)|(\s*$)/g,""); g整个字符串 }

  8. 笨方法学python--字符串和文本

    1print 变量 abc = False joke_string = "Isn't that joke so funny?! %r" print joke_string %abc ...

  9. Android OpenGL ES(十二):三维坐标系及坐标变换初步 .

    OpenGL ES图形库最终的结果是在二维平面上显示3D物体(常称作模型Model)这是因为目前的打部分显示器还只能显示二维图形.但我们在构造3D模型时必须要有空间现象能力,所有对模型的描述还是使用三 ...

  10. 视频 -> 帧 浅析

    原创:转载请注明出处 关于帧率 首先以下几个概念必须弄清楚 1.一个帧就是一个画面 2.视频有无数个帧组成 3.表达时间的量  CMTime 的定义: typedef struct { CMTimeV ...