795. Number of Subarrays with Bounded Maximum
题目描述
We are given an array A of positive integers, and two positive integers L and R (L <= R).
Return the number of (contiguous, non-empty) subarrays such that the value of the maximum array element in that subarray is at least L and at most R.
|
|
Note:
- L, R and A[i] will be an integer in the range [0, 10^9].
- The length of A will be in the range of [1, 50000].
题目大意
求最大值 >= L
、<= R
的所有子序列。
解题思路
通过
> R
将数组分割成多个子序列。
再通过< L
将数组分割计算,确保每个子序列中都存在至少一个满足>= L && <= R
。
代码
|
|