?
# | Author | Problem | Lang | Verdict | Time | Memory | Sent | Judged | |
---|---|---|---|---|---|---|---|---|---|
187487284 |
Practice: DaiRuiChen007 |
1672F1 - 14 | C++14 (GCC 6-32) | Accepted | 109 ms | 7224 KB | 2023-01-01 04:08:32 | 2023-01-01 04:08:32 |
// LUOGU_RID: 98400108 #include<bits/stdc++.h> using namespace std; const int MAXN=2e5+1; int a[MAXN],cnt[MAXN]; vector <int> buc[MAXN]; inline bool cmp(const int &id1,const int &id2) { if(cnt[a[id1]]==cnt[a[id2]]) return a[id1]>a[id2]; return cnt[a[id1]]>cnt[a[id2]]; } inline void solve() { int n; scanf("%d",&n); for(int i=1;i<=n;++i) buc[i].clear(),cnt[i]=0; for(int i=1;i<=n;++i) { scanf("%d",&a[i]); ++cnt[a[i]]; buc[cnt[a[i]]].push_back(i); } for(int i=1;i<=n;++i) { sort(buc[i].begin(),buc[i].end(),cmp); for(int j=1;j<(int)buc[i].size();++j) swap(a[buc[i][j-1]],a[buc[i][j]]); } for(int i=1;i<=n;++i) printf("%d ",a[i]); puts(""); } signed main() { int T; scanf("%d",&T); while(T--) solve(); return 0; }
?
?
?
?