STL离散化模板
for(int i=1;i<=n;++i) scanf("%d",&a[i]),b[i]=a[i];
sort(b+1,b+n+1);//排序
int len=unique(b+1,b+n+1)-b-1;//去重
for(int i=1;i<=n;++i) a[i]=lower_bound(b+1,b+len+1,a[i])-b;//二分查找
for(int i=1;i<=n;++i) scanf("%d",&a[i]),b[i]=a[i];
sort(b+1,b+n+1);//排序
int len=unique(b+1,b+n+1)-b-1;//去重
for(int i=1;i<=n;++i) a[i]=lower_bound(b+1,b+len+1,a[i])-b;//二分查找