class Solution(object):
def numSubarrayBoundedMax(self, nums, left, right):
"""
:type nums: List[int]
:type left: int
:type right: int
:rtype: int
"""
ans = 0
p1 = p2 = -1
for i in range(len(nums)):
if left <= nums[i] <= right:
p1 = i
elif nums[i] > right:
p1 = -1
p2 = i
if p1 != -1:
ans += p1 - p2
return ans