Enumerate each series of identical numbers in-place Given a list of strictly positive integers, go through each distinct number and replace all occurrences of it with successive indices (zero or one based) of a new series.

Examples

[] → []/[]

[42] → [0]/[1]

[7,7,7] → [0,1,2]/[1,2,3]

[10,20,30] → [0,0,0]/[1,1,1]

[5,12,10,12,12,10] → [0,0,0,1,2,1]/[1,1,1,2,3,2]

[2,7,1,8,2,8,1,8,2,8] → [0,0,0,0,1,1,1,2,2,3]/[1,1,1,1,2,2,2,3,3,4]

[3,1,4,1,5,9,2,6,5,3,5,9] → [0,0,0,1,0,0,0,0,1,1,2,1]/[1,1,1,2,1,1,1,1,2,2,3,2]
JavaScript (ES6), 26 bytes
1-indexed.

a=&gt;a.map(o=x=&gt;o[x]=-~o[x])

Try it online!
Commented
a =&gt;                // a[] = input array
  a.map(o =         // assign the callback function of map() to the variable o, so that
                    // we have an object that can be used to store the counters
    x =&gt;            // for each value x in a[]:
      o[x] = -~o[x] //   increment o[x] and yield the result
                    //   the '-~' syntax allows to go from undefined to 1
  )                 // end of map()