离散化
废话不多说直接代码
1 //2018年2月19日22:42:56 2 #include <iostream> 3 #include <cstdio> 4 #include <algorithm> 5 using namespace std; 6 7 const int N = 100010; 8 9 int n, a[N], b[N]; 10 11 inline int read(){ 12 int x=0, f=1; char ch = getchar(); 13 while(ch<'0' || ch>'9'){if(ch == '-') f=-1; ch = getchar();} 14 while(ch>='0' && ch<='9'){ x = x*10+ch-'0'; ch = getchar();} 15 return x*f; 16 } 17 18 int main(){ 19 n = read(); 20 for(int i=1;i<=n;i++){ 21 a[i] = b[i] = read(); 22 } 23 sort(b+1, b+n+1); 24 for(int i=1;i<=n;i++) 25 a[i] = lower_bound(b+1, b+n+1, a[i]) - b; 26 for(int i=1;i<=n;i++) 27 printf("%d ", a[i]); 28 29 return 0; 30 }