If all your integers have the same frequency, then a fair approximation to optimal compression will be ceil(log2(k)) bits per integer. You can get a bit array from them at a constant time.
If k is painfully small (e.g. 3), the above method can take up enough space. But you can combine a fixed number of your small integers with a base- k number, which can fit more effectively into a fixed number of bits (you can also conveniently place the result in a standard-sized word). In any case, you can also access this encoding in constant time.
If your integers do not have the same frequency, optimal compression can lead to variable bit rates from different parts of your input, so just accessing the array will not work. In this case, an index structure is required for good random access performance: break the compressed data into pieces of convenient size, each of which can be unpacked sequentially, but this time it is limited by the block size.
If the frequency of each number is exactly the same, you can save some space by taking advantage of this, but this may not be enough to be useful.
The entropy of n random numbers in the range [0,k) is n log2(k) , which is log2(k) bits per number; this is the number of bits it takes to encode your numbers without using the exact frequency.
The entropy of distinguishable permutations f copies each of the elements k (where n=f*k ):
log2( n!/(f!)^k ) = log2(n!) - k * log2(f!)
Using the Stirling approximation (which is good here only if n and f large), gives:
~ n log2(n) - n log2(e) - k ( f log2(f) - f log2(e) ) = n log2(n) - n log2(e) - n log2(f) + n log2(e) = n ( log2(n) - log2(f) ) = n log2(n/f) = n log2(k)
This means that if n large and k small, you wonβt get a significant amount of space using the exact frequency of your input.
The general error from the Stirling approximation is above O(log2(n) + k log2(f)) , which O(log2(n)/n + log2(f)/f) is encoded by the number. This means that if your k so large that your f is small (i.e., each individual number has only a small number of copies), you can save some space with smart encoding. However, the question indicates that k is actually small.