#P9912. Island Counting
Island Counting
Island Counting
Mr. Malnar has a topographic map where each of the positions in a row has an altitude above sea level. The sea level may rise. You are given queries; for the -th query, if the sea level rises by meters, determine how many islands are formed in the segment . An island is defined as a maximal contiguous segment where every position has an altitude greater than .
For example, consider the region shown in the left image: in the interval , there are two islands: and . In the right image, there are four islands: , , , and .
inputFormat
The first line contains two integers and , denoting the number of positions and the number of queries respectively.
The second line contains integers () representing the altitude of each position.
Then lines follow, each containing three integers , , and , where is the rise in sea level for the query.
outputFormat
For each query, output a single integer on a new line representing the number of islands formed in the interval when the sea level rises by meters.
sample
5 2
1 3 2 4 2
2 5 2
1 3 1
2
1
</p>