#include <iostream> #include <vector> #include <unordered_map> #include <algorithm> using namespace std; int main() { int n; cin >> n; vector<int> a(n), b(n); unordered_map<int, int> rankMap; for(int i = 0; i < n; ++i) { cin >> a[i]; b[i] = a[i]; } sort(b.begin(), b.end()); for(int i = 0; i < n; ++i) { rankMap[b[i]] = i+1; } for(int i = 0; i < n; ++i) { cout << rankMap[a[i]] << " "; } return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter