<p>Given an integer array&nbsp;<code>nums</code>, return <em>the number of longest increasing subsequences.</em></p>

<p><strong>Notice</strong> that the sequence has to be <strong>strictly</strong> increasing.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,3,5,4,7]
<strong>Output:</strong> 2
<strong>Explanation:</strong> The two longest increasing subsequences are [1, 3, 4, 7] and [1, 3, 5, 7].
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [2,2,2,2,2]
<strong>Output:</strong> 5
<strong>Explanation:</strong> The length of the longest increasing subsequence is 1, and there are 5 increasing subsequences of length 1, so output 5.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 2000</code></li>
	<li><code>-10<sup>6</sup> &lt;= nums[i] &lt;= 10<sup>6</sup></code></li>
	<li>The answer is guaranteed to fit inside a 32-bit integer.</li>
</ul>

class BIT:
    def __init__(self, n):
        self.n = n
        self.tree = [0] * (n + 1)
        self.cnt = [0] * (n + 1)

    def update(self, index, val, cnt):
        i = index + 1
        while i < len(self.tree):
            if self.tree[i] < val:
                self.tree[i] = val
                self.cnt[i] = cnt
            elif self.tree[i] == val:
                self.cnt[i] += cnt
            i += (i & -i)

    def query(self, i):
        res = 0
        cnt = 0
        while i:
            if self.tree[i] > res:
                res = self.tree[i]
                cnt = self.cnt[i]
            elif self.tree[i] == res:
                cnt += self.cnt[i]
            i &= (i - 1)
        return res, cnt

class Solution:
    def findNumberOfLIS(self, nums: List[int]) -> int:
        memo = {num : i for i, num in enumerate(sorted(set(nums)))}
        n = len(memo)
        ft = BIT(n)
        mx_len = 0
        res = 0
        for num in nums:
            prev_mx, prev_cnt = ft.query(memo[num])
            prev_cnt = max(prev_cnt, 1)
            if prev_mx + 1 == mx_len:
                res += prev_cnt
            elif prev_mx + 1 > mx_len:
                mx_len = prev_mx + 1
                res = prev_cnt
            ft.update(memo[num], prev_mx + 1, prev_cnt)
        return res
16800