Mammals were inherently better competitors than the dinosaurs; the K-P impact simply sped up the replacement, which was already well under way.
By chance, the K-P impact caused extinction of the dinosaurs but did not greatly affect the small, nocturnal, scavenging mammals. The release from competition allowed the mammals to diversify.
Both mammals and dinosaurs survived the asteroid, but the mammals were much better adapted to the new environments created by the impact and therefore underwent adaptive radiation.
Mammalian diversity increased dramatically prior to the impact, but the population sizes of every species remained small until after the dinosaurs were extinct.