Collective dynamics of stock market efficiency