Let $S$ be a sequence of $k$ many numbers. The position of the number in the $S$ matters. In the $S$ there are only $j$ many different numbers are there means $S$ contains many duplicates. Position is a query which needed to be answered, position(i) returns the element at position $i$ in $S$.
Trivial way to store them is using array which will takes $O(S)$ space and position can be solved in $O(1)$ time.
I am looking for a representation that takes $O(j)$ space (or somewhere near to it) and such that position can be solved in $O(1)$(even in more time is also ok)?
Please suggest some papers also.