링크 : https://www.acmicpc.net/problem/18870
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n, x, cnt = 0;
vector<pair<int, int>> v, ans;
int main()
{
cin >> n;
for (int i = 0; i < n; i++){
cin >> x;
v.push_back({x, i});
}
sort(v.begin(), v.end());
ans.push_back({v[0].second, 0});
for (int i = 1; i < n; i++){
if (v[i-1].first == v[i].first){
ans.push_back({ v[i].second, cnt });
}
else {
ans.push_back({ v[i].second, ++cnt });
}
}
sort(ans.begin(), ans.end());
for (int i = 0; i < n; i++)
cout << ans[i].second << " ";
}