Optimal rank and select queries on dictionary-compressed text