离散化 发表于 2019-10-05 | 阅读次数: 本文字数: 5.2k | 阅读时长 ≈ 5 分钟 直接上代码点击显/隐代码 1234567891011121314151617181920212223242526272829303132333435363738#include<fstream>#include<iostream>#include<algorithm>using namespace std;struct shu{ int xuhao,shuzi,ans;};int n;shu a[100005];bool cmp1(shu a,shu b){ return a.shuzi<b.shuzi;}bool cmp2(shu a,shu b){ return a.xuhao<b.xuhao;}int main(){ cin>>n; for(int i=1;i<=n;i++) { cin>>a[i].shuzi; a[i].xuhao=i; } sort(a+1,a+n+1,cmp1); a[1].ans=1; for(int i=2;i<=n;i++) { if(a[i].shuzi==a[i-1].shuzi) a[i].ans=a[i-1].ans; else a[i].ans=i; } sort(a+1,a+n+1,cmp2); for(int i=1;i<=n;i++) cout<<a[i].ans<<' '; cout<<endl; return 0;}