K (ngn/k), 19 bytes
1+?{*(++,\x)?,x}',\ Modeled after @Jonah's J answer.
{...}',\for each prefix of the (implicit) input...(++,\x)expand each prefix (of the current passed-in prefix) to the full length of that prefix (e.g., transform1 1 2from(1;1 1;1 1 2)into(1 1 1;1 1 1;1 1 2))*(...)?,xget the index of the first transformed prefix that matches the prefix itself1+?{...}add one to the distinct indices