Intrusion and extrusion of a liquid on nanostructured surfaces