#C8124. Count Shorter People

    ID: 52072 Type: Default 1000ms 256MiB

Count Shorter People

Count Shorter People

Given a list of heights of people in a queue, the task is to count, for each person, how many people standing in front of them are shorter than the person.

Formally, for an array of heights \(a_0, a_1, \dots, a_{n-1}\), for each index \(i\) (where \(0 \le i < n\)), calculate the value:

[ result[i] = |{ j \mid 0 \le j < i \text{ and } a_j < a_i }| ]

For example, if the input is 140 145 150 140 150, the output is 0 1 2 0 3 because:

  • For the first person, no one is in front, so 0.
  • For the second person (145), only 140 is in front and 140 < 145, so 1.
  • For the third person (150), both 140 and 145 are shorter, so 2.
  • For the fourth person (140), there is no one shorter in front (140 is not less than 140), so 0.
  • For the fifth person (150), three people in front (140, 145, and 140) are shorter, so 3.

inputFormat

The input is provided via standard input (stdin) with the following format:

  1. An integer n representing the number of people in the queue.
  2. A line with n space-separated integers representing the heights of the people.

outputFormat

Output a single line (via standard output, stdout) containing n space-separated integers. The i-th integer should be the count of people in front of the i-th person whose height is strictly less than the i-th person's height.

## sample
5
140 145 150 140 150
0 1 2 0 3

</p>