Without making any consideration on the suitability of the thought structure, I propose an idea to obtain the indices as desired by the OP.
The implementation changes if, by any chance, the indexes to be used are sorted, for example, in ascending order.
a=[11,5,2,3,7,1]
function relindex(a)
ad=similar(a)
for i in eachindex(a)
ad[i]=a[i]-count(<(a[i]),a[begin:i])
end
ad
end
relindex(a)
function sortrelindex(a)
ad=similar(a)
for i in eachindex(a)
ad[i]=a[i]-i+1
end
ad
end
sortrelindex(sort(a))