#K52362. Count Greater Elements to Right

    ID: 29293 Type: Default 1000ms 256MiB

Count Greater Elements to Right

Count Greater Elements to Right

Given an array of (n) integers, your task is to construct an array (D) of size (n) such that for each index (i), (D[i]) is equal to the number of elements greater than (A[i]) that appear to the right of (A[i]) in the given array.

In other words, for each (i) (where (0 \leq i < n)), calculate the count of indices (j) such that (j > i) and (A[j] > A[i]).

For example, given the array [3, 4, 2, 7, 5], the output should be [3, 2, 2, 0, 0] because:
(3) has three numbers greater than it to the right (4, 7, 5),
(4) has two (7, 5),
(2) has two (7, 5), and the last two elements have no numbers to their right that are greater.

inputFormat

The first line contains an integer (n) which denotes the number of elements in the array. The second line contains (n) space-separated integers representing the array (A).

outputFormat

Output a single line containing (n) space-separated integers representing the array (D), where (D[i]) is the number of elements greater than (A[i]) to its right.## sample

5
3 4 2 7 5
3 2 2 0 0

</p>