#FT0000153. Nhìn thấy các tòa nhà 2 (Buildings 2)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Nhìn thấy các tòa nhà 2 (Buildings 2)
Buildings 2
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are buildings from west to east with heights . Building is visible from building if there is no index with and . For each query , count buildings that are visible from both buildings and . Building itself and all buildings to its west are excluded.
Input
The first line contains . The next line contains heights. Each of the next lines contains .
Output
Print one integer per query, the number of qualifying buildings.
Subtasks
- Subtask 1 (20 points): ; ; Heights are a permutation of ; all heights are distinct, and each query satisfies .
- Subtask 2 (30 points): ; ; Heights are a permutation of ; all heights are distinct, and each query satisfies .
- Subtask 3 (50 points): ; ; Heights are a permutation of ; all heights are distinct, and each query satisfies .
Examples
Example 1
Input
5 3
2 1 4 3 5
1 2
3 5
1 4
Output
2
0
1
Explanation
For , buildings 3 and 5 are visible from both endpoints; building 4 is blocked by 3. For there are no buildings beyond 5. For , only building 5 lies to the east and is visible.
Example 2
Input
4 2
1 4 2 3
1 2
2 3
Output
0
1
Explanation
For the tall building 2 blocks both later buildings from 1. For , building 4 has height 3 and no intervening building is taller than 3, so it is visible from both.