SalesforceOA #43
Visible Towers
估计中等可在线判题
考点(AI 标注)单调栈与堆
Towers stand in a row. Tower x is visible from tower y if and only if every tower between them is strictly shorter than the target tower x. The observer y's own height imposes no restriction. For each tower, output the total number of towers it can see to its left and right, excluding itself.
输入格式
The input gives n and n heights. The original has no numeric bounds; this site adds 1≤n≤200000, 0≤height[i]≤10^9. Duplicate heights are allowed.
输出格式
Output the n visible-tower counts in original position order, separated by spaces or newlines.
样例 1
输入:
4
5 2 10 1
输出:
2 2 3 1
样例 2
输入:
3
1 2 3
输出:
2 2 1
样例 3
输入:
1
7
输出:
0
样例说明
The outputs of the three public examples are, in order: 2 2 3 1; 2 2 1; 0. They have been checked by independent enumeration or direct simulation.