K-Pg events facilitated lineage transitions between terrestrial and aquatic ecosystems