The chief executives of Microsoft and Meta defended massive spending that they said was key to staying competitive.