Provably efficient representation selection in Low-rank Markov Decision Processes: from online to offline RL