class Solution:
def findNumberOfLIS(self, nums: List[int]) -> int:
n=len(nums)
stk=[]
piles=[]
for num in nums:
if not stk:
stk.append([(num,1)])
piles.append(num)
else:
idx=len(stk)
if stk[-1][-1][0]>=num:
idx = bisect_left(piles,num)
piles[idx]=num
freq=0
for val,count in stk[idx-1]:
if num>val:
freq+=count
if freq==0:freq=1
if stk[-1][-1][0]<num:
stk.append([(num,freq)])
piles.append(num)
else:
stk[idx].append([num,freq])
res=0
for val,count in stk[-1]:
res+=count
return res
stk的每次层是相同长度的
piles 相当于经典递增序列中维护的递增序列