// Forward declaration of compare API.
// bool compare(int a, int b);
// return bool means whether a is less than b.
class Solution {
public:
vector<int> specialSort(int n) {
vector<int> ans;
ans.push_back(1);
for(int idx = 2; idx <= n; idx++){
int l = 0, r = ans.size();
while(l < r){
int mid = (l + r) >> 1;
if(compare(idx, ans[mid])) r = mid; else l = mid + 1;
}
ans.push_back(idx);
for(int j = ans.size()-2; j >= r; j--) swap(ans[j], ans[j + 1]);
}
return ans;
}
};