# 计算右侧小于当前元素的个数

<p>给你`一个整数数组 <code>nums</code><em> </em>，按要求返回一个新数组&nbsp;<code>counts</code><em> </em>。数组 <code>counts</code> 有该性质： <code>counts[i]</code> 的值是&nbsp; <code>nums[i]</code> 右侧小于&nbsp;<code>nums[i]</code> 的元素的数量。</p>

<p>&nbsp;</p>

<p><strong>示例 1：</strong></p>

<pre>
<strong>输入：</strong>nums = [5,2,6,1]
<strong>输出：</strong><code>[2,1,1,0] 
<strong>解释：</strong></code>
5 的右侧有 <strong>2 </strong>个更小的元素 (2 和 1)
2 的右侧仅有 <strong>1 </strong>个更小的元素 (1)
6 的右侧有 <strong>1 </strong>个更小的元素 (1)
1 的右侧有 <strong>0 </strong>个更小的元素
</pre>

<p><strong>示例 2：</strong></p>

<pre>
<strong>输入：</strong>nums = [-1]
<strong>输出：</strong>[0]
</pre>

<p><strong>示例 3：</strong></p>

<pre>
<strong>输入：</strong>nums = [-1,-1]
<strong>输出：</strong>[0,0]
</pre>

<p>&nbsp;</p>

<p><strong>提示：</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
	<li><code>-10<sup>4</sup> &lt;= nums[i] &lt;= 10<sup>4</sup></code></li>
</ul>


## template

```python
class Solution:
    def countSmaller(self, nums: List[int]) -> List[int]:
        n = len(nums)
        if n == 0:
            return []

        numsarr = [[nums[i], i] for i in range(n)]

        res = [0 for _ in range(n)]

        def merge(left, right):

            if left == right:
                pass
            else:

                mid = left + (right - left) // 2

                merge(left, mid)
                merge(mid + 1, right)

                temp = []

                i = left
                j = mid + 1

                while i <= mid and j <= right:

                    if numsarr[i][0] <= numsarr[j][0]:
                        temp.append(numsarr[j])
                        j += 1

                    else:
                        temp.append(numsarr[i])
                        res[numsarr[i][1]] += right - j + 1
                        i += 1

                while i <= mid:
                    temp.append(numsarr[i])
                    i += 1
                while j <= right:
                    temp.append(numsarr[j])
                    j += 1

                numsarr[left : right + 1] = temp[:]

        merge(0, n - 1)
        return res



```

## 答案

```python

```

## 选项

### A

```python

```

### B

```python

```

### C

```python

```