heights and a list of requests requests. A peak of a segment is an element that is strictly greater than both of its neighbours inside that segment. The first and last elements of a segment can never be peaks.
There are two kinds of requests:
- [1, l, r]: count the peaks in the segment heights[l..r] (inclusive);
- [2, i, v]: set heights[i] to v.
Process the requests in order and return the list of answers to the requests of the first kind.heights=[2, 5, 3, 6, 1], requests=[[1, 0, 4], [2, 2, 7], [1, 0, 4]] → [2, 1]
At first the peaks are 5 and 6, so the answer is 2. Then the third height becomes 7: the array is [2, 5, 7, 6, 1] and the only peak is 7.
heights=[1, 4, 2, 4, 1], requests=[[1, 1, 3], [1, 0, 2]] → [0, 1]
In the segment [4, 2, 4] the ends cannot be peaks and 2 is lower than its neighbours, so the answer is 0. In [1, 4, 2] the 4 is a peak, so the answer is 1.
heights=[3, 3, 3], requests=[[2, 1, 4], [1, 0, 2]] → [1]
[1, l, r]: 0 ≤ l ≤ r ≤ len(heights) − 1[2, i, v]: 0 ≤ i ≤ len(heights) − 1, 1 ≤ v ≤ 10⁵heights=[2, 5, 3, 6, 1], requests=[[1, 0, 4], [2, 2, 7], [1, 0, 4]]
[2, 1]
Run checks the first 3 tests in your browser. Submit checks all 86 tests on the server, hidden ones included.