提交时间:2025-05-24 16:41:45

运行 ID: 324130

#include<bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector<int> scores(N), sorted_scores(N); for(int i = 0; i < N; ++i) { cin >> scores[i]; sorted_scores[i] = scores[i]; } sort(sorted_scores.begin(), sorted_scores.end(), greater<int>()); vector<int> ranks(N); ranks[0] = 1; for(int i = 1; i < N; ++i) { if(sorted_scores[i] == sorted_scores[i-1]) { ranks[i] = ranks[i-1]; } else { ranks[i] = i + 1; } for(int score : scores) { auto it = lower_bound(sorted_scores.begin(), sorted_scores.end(),score, greater<int>()); int pos = it - sorted_scores.begin(); cout << ranks[pos] << "\n"; } return 0; }