跳到正文

个人记录

离散化

zyx3838约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年5月25日
收录
2025年12月12日
更新
2026年11月10日
篇幅
约 1 分钟

版本

  1. v1当前
C++
vector<int> tmp(n+1);
for(int i=1;i<=n;i++)
{
	cin>>arr[i];
	tmp[i]=arr[i];
}
sort(tmp.begin()+1,tmp.end());
int m=unique(tmp.begin()+1,tmp.end())-(tmp.begin()+1);
for(int i=1;i<=n;i++)
{
	rnk[i]=lower_bound(tmp.begin()+1,tmp.begin()+m+1,arr[i])-tmp.begin();
}
原文