I want to efficiently count the replications of each element in a very long vector.

This simple idiom does exactly what I want

r← +/v∘.=v

but unfortunately the cost of that goes up with the square of the length of the vector, so it is completely unusable for extremely long vectors.

The multiset operator helps.

ru← ∪⍦v

That does efficiently count the replications of the unique elements.

But then I need to redistribute those values back to their positions in the original vector.

Again, there are lots of fairly simple idioms that can do that, but they are usually also very inefficient on very long vectors.

I'm looking for one which is readily usable on very long vectors.

There must be a simple method I haven't yet thought of.