离散化
方法两种:
int lsh[maxn],cnt,num[maxn],n;
for(int i=1;i<=n;i++){
cin>>num[i];
lsh[i] = num[i];
}
sort(lsh+1,lsh+n+1);
//去重
cnt = unique(lsh+1,lsh+n+1)-lsh-1;
for(int i=1;i<=n;i++){
//寻找第一个小于等于num[i]并返回下标
num[i] = lower_bound(lsh+1,lsh+cnt+1,num[i]) - lsh;
}
struct Node {
int data,id;
bool operator < (const Node &a) const {
return data < a.data;
}
};
Node num[maxn];
int rank[maxn],n;
for(int i=1;i<=n;i++){
cin>>num[i].data;
num[i].id = i;
}
sort(num+1,num+n+1);
for(int i=1;i<=n;i++){
rank[num[i].id] = i;
}