#3187
Peaks in Array
hard · 27.2% accepted · 142 likes · top 5%
array · binary indexed tree · segment tree
Description
A peak in an array arr is an element that is greater than its previous and next element in arr.
You are given an integer array nums and a 2D integer array queries.
You have to process queries of two types:
- queries[i] = [1, li, ri], determine the count of peak elements in the subarray nums[li..ri].
- queries[i] = [2, indexi, vali], change nums[indexi] to vali.
Return an array answer containing the results of the queries of the first type in order.
Notes:
- The first and the last element of an array or a subarray cannot be a peak.
Solution