Problem Statement There are N N buildings, Building 1 1, Building 2 2, … …, Building N…
- User
Problem Statement There are N N buildings, Building 1 1, Building 2 2, … …, Building N N, arranged in a line in this order. The height of Building i i ( 1 ≤ i ≤ N ) (1≤i≤N) is H i H i .
For each i
1 , 2 , … , N i=1,2,…,N, find the number of integers j j ( i < j ≤ N ) (i<j≤N) satisfying the following condition:
There is no building taller than Building j j between Buildings i i and j j. Constraints 1 ≤ N ≤ 2 × 1 0 5 1≤N≤2×10 5
1 ≤ H i ≤ N 1≤H i ≤N H i ≠ H j
( i ≠ j ) H i
=H j (i =j) All input values are integers. Input The input is given from Standard Input in the following format:
N N H 1 H 1
H 2 H 2
… … H N H N
Output For each i
1 , 2 , … , N i=1,2,…,N, let c i c i be the number of j j satisfying the condition. Print c 1 , c 2 , … , c N c 1 ,c 2 ,…,c N in order, separated by spaces.
Sample 1 Inputcopy Outputcopy 5 2 1 4 3 5 3 2 2 1 0 For i
1 i=1, the integers j j satisfying the condition are 2 2, 3 3, and 5 5: there are three. (Between Buildings 1 1 and 4 4, there is a building taller than Building 4 4, which is Building 3 3, so j
4 j=4 does not satisfy the condition.) Therefore, the first number in the output is 3 3.
Sample 2 Inputcopy Outputcopy 4 1 2 3 4 3 2 1 0 Sample 3 Inputcopy Outputcopy 10 1 9 6 5 2 7 10 4 8 3 2 3 3 3 2 1 2 1 1 0 type dp in c++
- Assistant