Easy Orderded Set solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n#include <ext/pb_ds/assoc_container.hpp>\nusing namespace __gnu_pbds;\n\ntypedef pair<int, int> node;\ntypedef tree<node, null_type, less<node>,\n            rb_tree_tag, tree_order_statistics_node_update> ordered_set;\n\n\nclass Solution {\npublic:\n    vector<int> resultArray(vector<int>& nums) {\n        ordered_set s1;\n        ordered_set s2;\n        s1.insert(node(nums[0], 0));\n        s2.insert(node(nums[1], 0));\n        int siz1 = 1, siz2 = 1;\n\n        int n = nums.size();\n\n        for(int i = 2; i < n; i++){\n            int cnt = nums[i];\n            int n1 = siz1 - s1.order_of_key(node(cnt, n));\n            int n2 = siz2 - s2.order_of_key(node(cnt, n));\n\n            cout << n1 << \' \' << n2 << endl;\n\n            if(n1 > n2){\n                s1.insert(node(cnt, siz1));\n                siz1++;\n            }\n            else if(n2 > n1){\n                s2.insert(node(cnt, siz2));\n                siz2++;\n            }\n            else if(siz2 < siz1){\n                s2.insert(node(cnt, siz2));\n                siz2++;\n            }\n            else{\n                s1.insert(node(cnt, siz1));\n                siz1++;\n            }\n        }\n\n        map<int, int> mp1;\n        map<int, int> mp2;\n        for(auto it: s1) mp1[it.second] = it.first;\n        for(auto it: s2) mp2[it.second] = it.first;\n\n        vector<int> ans;\n\n        for(auto it: mp1) ans.push_back(it.second);\n        for(auto it: mp2) ans.push_back(it.second);\n\n\n        return ans;\n    }\n};\n```
['C++']