They build their ant hills with very good drainage. Their anthills are filled with tunnels that allow water to drain very quickly. Certain types of ants build hills with hard roofs made out of dirt.
Rain water runs off the hard covering like it does from the roof of a house.
If an anthill floods, some ants will drown, but most will survive by clinging to sticks or leaves and riding them like surfboards on the floodwater. Ants will often have to rebuild their hill after a flood because the wet soil collapses and closes the tunnels.