cpp
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> \n#include <ext/pb_ds/tree_policy.hpp> \nusing namespace __gnu_pbds; \nclass Solution {\npublic:\n\n  \n    #define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> \n\n    vector<int> resultArray(vector<int>& nums) {\n        vector<int> a, b;\n        ordered_set a1,b1;\n        int n = nums.size();\n        a.push_back(nums[0]);\n        b.push_back(nums[1]);\n        a1.insert(nums[0]), b1.insert(nums[1]);\n        \n        for(int i=2;i<n;i++){\n            int ind1=a1.order_of_key(nums[i]+1);\n            int ind2=b1.order_of_key(nums[i]+1);\n            int  x = a.size()-ind1;\n            int y = b.size()-ind2;\n            \n            if(x>y){a1.insert(nums[i]),a.push_back(nums[i]);}\n            else if(y>x){b1.insert(nums[i]), b.push_back(nums[i]);}\n            else if(x==y && a.size()<b.size()){a1.insert(nums[i]),a.push_back(nums[i]);}\n            else if(x==y && a.size()>b.size()){b1.insert(nums[i]),b.push_back(nums[i]);}\n            else {a1.insert(nums[i]),a.push_back(nums[i]);}\n        }\n        vector<int> ans;\n        for(auto x: a)ans.push_back(x);\n        for(auto x: b)ans.push_back(x);\n        \n        return ans;\n    }\n};\n```
['C++']