#STK0000080. Tầm nhìn tòa nhà (Tower Visibility)
Tầm nhìn tòa nhà (Tower Visibility)
Tower Visibility
Source: Baekjoon Online Judge
Version: Phuoc Hung OJ Extended
Problem Statement
There are buildings on a line, numbered through , with equal spacing between adjacent buildings. From building , only buildings with are candidates. Building is visible from if every building strictly between and has height less than ; if an intermediate building has height at least , then is blocked. For each building, determine the total number of visible buildings on both sides and, if any exists, the index of the nearest visible building. If two nearest buildings are at the same distance, choose the smaller index.
Input
The first line contains . The second line contains heights .
Output
For each from to , print one line. If no building is visible, print 0. Otherwise print the number of visible buildings and the index of the nearest one.
Subtasks
- Subtask 1 (30 points): ; all other conditions are unchanged.
- Subtask 2 (70 points): , .
Examples
Input
8
3 7 1 6 3 5 1 7
Output
1 2
0
3 2
2 2
4 4
3 4
4 6
0
Explanation
The heights are .
The visible buildings from each position are:
- Building : sees building ; count , nearest index .
- Building : no taller visible building; print
0. - Building : sees buildings ; count . Buildings and are both one position away, so choose the smaller index .
- Building : sees buildings ; both are two positions away, so choose .
- Building : sees buildings ; the nearest are and , both one position away, so choose .
- Building : sees buildings ; the nearest is .
- Building : sees buildings ; the nearest are and , both one position away, so choose .
- Building : no taller visible building; print
0.
These counts and nearest indices give exactly the sample output.