CP approach || pbds data structure  || Intuitive code || C++ || easy pp
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nUse 2 policy based data structure st1,st2 for inserting elements same as 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nUse 2 policy based data structure st1,st2 for inserting elements same as in two different vectors v1,v2 according to different simple if else conditions , pbds is data structure that helps in insertion ,deletion, particular index of element finding {not supported by simple set}, element less than particular element , element greater than particular element in st1,st2.\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<bits/stdc++.h>\n#include<ext/pb_ds/assoc_container.hpp>\n#include<ext/pb_ds/tree_policy.hpp>\n#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> \nusing namespace __gnu_pbds; // pbds\nusing namespace std ;\ntypedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key\nclass Solution {\npublic:\n    vector<int> resultArray(vector<int>& nums){\n        int n=nums.size();\n        pbds st1,st2;\n        vector<int> v1,v2;\n        st1.insert({nums[0],0});\n        v1.push_back(nums[0]);\n        st2.insert({nums[1],1});\n        v2.push_back(nums[1]);\n        for(int i=2;i<n;i++){\n            int sz1=v1.size();\n            int sz2=v2.size();\n            int idx1=st1.order_of_key({nums[i]+1,-1});\n            int idx2=st2.order_of_key({nums[i]+1,-1});\n            int diff1=sz1-idx1+1;\n            int diff2=sz2-idx2+1;\n            if(diff1>diff2){\n                v1.push_back(nums[i]);\n                st1.insert({nums[i],i});\n            }else if(diff1<diff2){\n                v2.push_back(nums[i]);\n                st2.insert({nums[i],i});\n            }else if(diff1==diff2 and sz1<sz2){\n                v1.push_back(nums[i]);\n                st1.insert({nums[i],i});\n            }else if(diff1==diff2 and sz1>sz2){\n                v2.push_back(nums[i]);\n                st2.insert({nums[i],i});\n            }else if(diff1==diff2 and sz1==sz2){\n                v1.push_back(nums[i]);\n                st1.insert({nums[i],i});\n            }\n        }\n        vector<int> arr;\n        for(auto it:v1){\n            arr.push_back(it);\n        }\n        for(auto it:v2){\n            arr.push_back(it);\n        }\n        return arr;\n    }\n};\n```
['C++']