Tap here to switch tabs
Problem
Submissions

Problem: Peaks in Array

Try to solve the Peaks in Array problem.

Statement

An element in an array is called a peak if it is strictly greater than its adjacent left and right neighbors.

You are given an integer array nums and a 2D integer array queries.

Process each query in queries, which can be one of the following two types:

  • [1,li,ri][1, l_i, r_i]: Count the number of peak elements in the subarray nums[l_i..r_i].

  • [2,indexi,vali][2, index_i, val_i]: Update the value of nums[index_i] to val_i.

Return an array containing the results of all type 1 queries in the order they are processed.

Note: The first and last elements of any subarray are not considered peaks.

Constraints:

  • 3≤3 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤105\leq 10^5

  • 1≤1 \leq queries.length ≤105\leq 10^5

  • queries[i][0] =1= 1 or queries[i][0] =2= 2

  • For all i such that queries[i][0] =1= 1: 0≤0 \leq queries[i][1] ≤\leq queries[i][2] ≤\leq nums.length −1- 1

  • For all i such that queries[i][0] =2= 2: 0≤0 \leq queries[i][1] ≤\leq nums.length −1- 1, 1≤1 \leq queries[i][2] ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Peaks in Array

Try to solve the Peaks in Array problem.

Statement

An element in an array is called a peak if it is strictly greater than its adjacent left and right neighbors.

You are given an integer array nums and a 2D integer array queries.

Process each query in queries, which can be one of the following two types:

  • [1,li,ri][1, l_i, r_i]: Count the number of peak elements in the subarray nums[l_i..r_i].

  • [2,indexi,vali][2, index_i, val_i]: Update the value of nums[index_i] to val_i.

Return an array containing the results of all type 1 queries in the order they are processed.

Note: The first and last elements of any subarray are not considered peaks.

Constraints:

  • 3≤3 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤105\leq 10^5

  • 1≤1 \leq queries.length ≤105\leq 10^5

  • queries[i][0] =1= 1 or queries[i][0] =2= 2

  • For all i such that queries[i][0] =1= 1: 0≤0 \leq queries[i][1] ≤\leq queries[i][2] ≤\leq nums.length −1- 1

  • For all i such that queries[i][0] =2= 2: 0≤0 \leq queries[i][1] ≤\leq nums.length −1- 1, 1≤1 \leq queries[i][2] ≤105\leq 10^5