#P9912. Island Counting

    ID: 23057 Type: Default 1000ms 256MiB

Island Counting

Island Counting

Mr. Malnar has a topographic map where each of the nn positions in a row has an altitude hih_i above sea level. The sea level may rise. You are given qq queries; for the ii-th query, if the sea level rises by xix_i meters, determine how many islands are formed in the segment [li,ri][l_i, r_i]. An island is defined as a maximal contiguous segment where every position has an altitude greater than xix_i.

For example, consider the region shown in the left image: in the interval [2,5][2,5], there are two islands: [2,2][2,2] and [4,5][4,5]. In the right image, there are four islands: [1,1][1,1], [4,4][4,4], [8,8][8,8], and [10,10][10,10].

inputFormat

The first line contains two integers nn and qq (1n,q105)(1 \leq n, q \leq 10^5), denoting the number of positions and the number of queries respectively.

The second line contains nn integers h1,h2,,hnh_1, h_2, \ldots, h_n (0hi1090 \leq h_i \leq 10^9) representing the altitude of each position.

Then qq lines follow, each containing three integers lil_i, rir_i, and xix_i (1lirin,0xi109)(1 \leq l_i \leq r_i \leq n, 0 \leq x_i \leq 10^9), where xix_i 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 [li,ri][l_i, r_i] when the sea level rises by xix_i meters.

sample

5 2
1 3 2 4 2
2 5 2
1 3 1
2

1

</p>