Multiset and Binary Search - Easy
IntuitionWe just need to simulate what the question is asking.ApproachAs we need to find number of greater elements, it will be easier to do so using a ordered
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
We just need to simulate what the question is asking. 

# Approach
<!-- Describe your approach to solving the problem. -->
As we need to find number of greater elements, it will be easier to do so using a ordered multiset and binary search, we can directly find the correct place for a current element in it, directly finding number of greater elements in `O(log(N))` complexity.

# Complexity
- Time complexity: O(N * 2 * log(N))
    log(N) for insertion into multiset and log(N) for binary search
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(2 * N)
    Multiset and answer lists.
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python3 []
class Solution:
    def resultArray(self, nums):
        a, b = SortedList([nums[0]]), SortedList([nums[1]])
        arr1, arr2 = [nums[0]], [nums[1]]

        for i in range(2, len(nums)):
            x1 = len(a) - a.bisect_right(nums[i])
            x2 = len(b) - b.bisect_right(nums[i])

            if x1 > x2:
                a.add(nums[i])
                arr1.append(nums[i])
            elif x1 < x2:
                b.add(nums[i])
                arr2.append(nums[i])
            elif len(a) > len(b):
                b.add(nums[i])
                arr2.append(nums[i])
            else:
                a.add(nums[i])
                arr1.append(nums[i])

        return arr1 + arr2

```
['Binary Search', 'Simulation', 'Ordered Set', 'Python3']