← 返回 nvidia 的题目列表Count Visible Towers
类型:online_judge
Problem: Count Visible Towers
You are given a row of n towers. The height of the i-th tower is height[i].
For two different towers i and j:
If j > i, tower i looks to the right to see tower j.
If j < i, tower i looks to the left to see tower j.
Tower j is visible from tower i if and only if every tower strictly between i and j has height strictly smaller than height[j].
In other words, while looking in one direction, a tower is visible if it is taller than all towers between itself and the observer. Adjacent towers are always visible because there is no tower between them.
Return an array ans of length n, where ans[i] is the total number of towers visible from tower i to both the left and the right.
Input Format
n
height[0] height[1] ... height[n-1]
Output Format
ans[0] ans[1] ... ans[n-1]
Constraints
1 <= n <= 2 * 10^5
1 <= height[i] <= 10^9
Heights may contain duplicates.
Example 1
Input:
5
3 1 2 5 4
Output:
3 3 3 3 1
Example 2
Input:
3
2 2 2
Output:
1 2 1
Example
Input
5
3 1 2 5 4
Output
3 3 3 3 1