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

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cmath>
  4. #include<string>
  5. #include<queue>
  6. #include<algorithm>
  7. #include<stack>
  8. #include<cstring>
  9. #include<vector>
  10. #include<list>
  11. #include<set>
  12. #include<map>
  13. using namespace std;
  14. #define ll long long
  15. #define mod 1000000007
  16. #define inf 999999999
  17. //#pragma comment(linker, "/STACK:102400000,102400000")
  18. int scan()
  19. {
  20. int res = , ch ;
  21. while( !( ( ch = getchar() ) >= '' && ch <= '' ) )
  22. {
  23. if( ch == EOF ) return << ;
  24. }
  25. res = ch - '' ;
  26. while( ( ch = getchar() ) >= '' && ch <= '' )
  27. res = res * + ( ch - '' ) ;
  28. return res ;
  29. }
  30. int a[];
  31. int flag[];
  32. int ans[];
  33. int main()
  34. {
  35. int x,y,z,i,t;
  36. scanf("%d",&x);
  37. for(i=;i<=x;i++)
  38. scanf("%d",&a[i]);
  39. for(i=;i<=x;i++)
  40. {
  41. memset(flag,,sizeof(flag));
  42. int maxx=,ji;
  43. for(t=i;t<=x;t++)
  44. {
  45. //cout<<maxx<<" "<<ji<<" "<<a[t]<<endl;
  46. flag[a[t]]++;
  47. if(flag[a[t]]>maxx)
  48. {
  49. maxx=flag[a[t]];
  50. ji=a[t];
  51. ans[ji]++;
  52. }
  53. else if(flag[a[t]]==maxx&&ji>a[t])
  54. {
  55. ji=a[t];
  56. ans[ji]++;
  57. }
  58. else
  59. ans[ji]++;
  60. }
  61. }
  62. for(i=;i<=x;i++)
  63. printf("%d ",ans[i]);
  64. return ;
  65. }

codeforces 351 div2 C. Bear and Colors 暴力的更多相关文章

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

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

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

  3. Codeforces#543 div2 B. Mike and Children(暴力?)

    题目链接:http://codeforces.com/problemset/problem/1121/B 题意 给n个数 最多的对数 其中每一对(i,j)的ai+aj都相等(不知道怎么解释.... 判 ...

  4. codeforces 356 div2 C.Bear and Prime 100 数学

    C. Bear and Prime 100 time limit per test 1 second memory limit per test 256 megabytes input standar ...

  5. codeforces 9 div2 C.Hexadecimal's Numbers 暴力打表

    C. Hexadecimal's Numbers time limit per test 1 second memory limit per test 64 megabytes input stand ...

  6. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  7. C. Bear and Colors

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

  8. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  9. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

随机推荐

  1. Python中如何获取类属性的列表

    这篇文章主要给大家介绍了在Python中如何获取类属性的列表,文中通过示例代码介绍的很详细,相信对大家的学习或者工作具有一定的参考借鉴价值,有需要的朋友可以参考借鉴,下面来一起看看吧. 前言 最近工作 ...

  2. HTML <input> <button> <submit>

    定义和用法 value 属性规定与按钮关联的初始值.请始终为按钮规定 type 属性,如果不填默认值是 "submit".submit其实就是一个特殊的button. <bu ...

  3. CloudFlare CDN折腾记-优化设置

    近期又在折腾了,常访问我博客的朋友或许页面曾出现过502错误提示,那是折腾CloudFlare CDN不成功的提示.在此先感谢坛子,在他的执着和求真之下,昨天晚上终于成功使用上CloudFlare C ...

  4. linux mail 发送邮件附件

    在很多场景中我们会使用Shell命令来发送邮件,而且我们还可能在邮件里面添加附件,本文将介绍使用Shell命令发送带附件邮件的几种方式,希望对大家有所帮助. 文章目录 1 使用mail命令 2 使用m ...

  5. 评价指标的局限性、ROC曲线、余弦距离、A/B测试、模型评估的方法、超参数调优、过拟合与欠拟合

    1.评价指标的局限性 问题1 准确性的局限性 准确率是分类问题中最简单也是最直观的评价指标,但存在明显的缺陷.比如,当负样本占99%时,分类器把所有样本都预测为负样本也可以获得99%的准确率.所以,当 ...

  6. jxl(Java Excel API) 使用方法 【1】

    //   构建Workbook对象, 只读Workbook对象  //   直接从本地文档创建Workbook  //   从输入流创建Workbook Workbook workbook = nul ...

  7. sql 中延时操作

    select 1; WAITFOR DELAY '00:00:30'; select 2; --执行完第一个之后会 延时 30秒,才会执行第二个sql

  8. SV中的Interface和Program

    Interface:SV中新定义的接口方式,用来简化接口连接,使用时注意在module或program之外定义interface,然后通过'include来添加进工程. interface  arb_ ...

  9. Hive sql和Presto sql的一些对比

    最近由于工作上和生活上的一些事儿好久没来博客园了,但是写博客的习惯还是得坚持,新的一年需要更加努力,困知勉行,终身学习,每天都保持空杯心态.废话不说,写一些最近使用到的Presto SQL和Hive ...

  10. python练习题,写一个方法 传进去列表和预期的value 求出所有变量得取值可能性(例如list为[1,2,3,4,5,6,12,19],value为20,结果是19+1==20只有一种可能性),要求时间复杂度为O(n)

    题目:(来自光荣之路老师)a+b==valuea+b+c=valuea+b+c+d==valuea+b+c+d+...=valuea和b....取值范围都在0-value写一个方法 传进去列表和预期得 ...