codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

643A.md (1761B)


      1 Source: https://codeforces.com/problemset/problem/643/A
      2 
      3 A. Bear and Colors
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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 *t**i*.
     22 
     23 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.
     24 
     25 There are ![](https://espresso.codeforces.com/3b3448b4c7e05c1a849a404dbedb24b7f5fc3c3c.png) non-empty intervals in total. For each color, your task is to count the number of intervals in which this color is dominant.
     26 
     27 Input
     28 
     29 The first line of the input contains a single integer *n* (1 ≤ *n* ≤ 5000) — the number of balls.
     30 
     31 The second line contains *n* integers *t*1, *t*2, ..., *t**n* (1 ≤ *t**i* ≤ *n*) where *t**i* is the color of the *i*-th ball.
     32 
     33 Output
     34 
     35 Print *n* integers. The *i*-th of them should be equal to the number of intervals where *i* is a dominant color.
     36 
     37 Examples
     38 
     39 Input
     40 
     41 ```
     42 4  
     43 1 2 1 2
     44 ```
     45 
     46 Output
     47 
     48 ```
     49 7 3 0 0
     50 ```
     51 
     52 Input
     53 
     54 ```
     55 3  
     56 1 1 1
     57 ```
     58 
     59 Output
     60 
     61 ```
     62 6 0 0
     63 ```
     64 
     65 Note
     66 
     67 In the first sample, color 2 is dominant in three intervals:
     68 
     69 * An interval [2, 2] contains one ball. This ball's color is 2 so it's clearly a dominant color.
     70 * An interval [4, 4] contains one ball, with color 2 again.
     71 * An interval [2, 4] contains two balls of color 2 and one ball of color 1.
     72 
     73 There are 7 more intervals and color 1 is dominant in all of them.