#P9912. [COCI 2023/2024 #2] Zatopljenje
[COCI 2023/2024 #2] Zatopljenje
Problem Description
Mr. Malnar has a topographic map that shows the elevation at each position in a certain area. Specifically, there are positions arranged in a line, and the -th position is meters above sea level.
Sea level may rise. You are given queries. For the -th query, you need to answer: if sea level rises by meters, how many islands will form in the interval ? An island is defined as a maximal segment in which every position has height greater than .

The figure above shows the first query of Sample 1 and the second query of Sample 2, respectively. In the left figure, there are two islands and in the interval , while in the right figure there are four islands , , , and .
Input Format
The first line contains two integers .
The second line contains integers , representing the initial elevation of each position.
The next lines each contain integers , representing one query.
Output Format
Output lines. The -th line contains one integer, the answer to the -th query.
6 3
2 4 2 3 4 1
2 5 2
3 5 3
3 4 4
2
1
0
10 3
5 0 3 4 2 0 1 6 3 5
3 9 1
1 10 3
1 10 2
2
4
3
Hint
Constraints
| Score | Special Property | |
|---|---|---|
| There exists such that $h_1\ge h_2\ge \cdots \ge h_p\le h_{p+1}\le \cdots \le h_n$ | ||
| None |
For all testdata, , , .
Translated by ChatGPT 5