#include <stdio.h>
#include <stdlib.h>
#include <string.h>
long long num_sort[1000001];
long long num1[1000001];
int binary(long long target,int size){
int start=0;
int end=size-1;
int idx=0;
while(start<=end){
int mid=(start+end)/2;
if(num_sort[mid]== target) return mid;
if(num_sort[mid] > target) {
end=mid-1;
} else {
start=mid+1;
}
}
}
int compare(const void *a,const void *b) {
long long A=*(long long*)a;
long long B=*(long long*)b;
if(A>B) return 1;
else return -1;
}
int main() {
int n;
scanf("%d",&n);
for(int i=0; i<n; i++) scanf("%lld",&num_sort[i]);
memcpy(num1, num_sort, sizeof(long long) * n);
qsort(num_sort,n,sizeof(long long),compare);
int unique=0;
if(n>0) {
unique=1;
for(int i=1; i<n; i++) {
if(num_sort[i] !=num_sort[i-1]){
num_sort[unique++]=num_sort[i];
}
}
}
for(int i=0; i<n; i++) {
printf("%d ",binary(num1[i],unique));
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: