classSolution:defincremovableSubarrayCount(self, a: List[int])->int:
n =len(a)
i =0while i < n -1and a[i]< a[i +1]:
i +=1if i == n -1:# 每个非空子数组都可以移除return n *(n +1)//2
ans = i +2
j = n -1while j == n -1or a[j]< a[j +1]:while i >=0and a[i]>= a[j]:
i -=1
ans += i +2
j -=1return ans