Investors have been pivoting toward high-quality megacap stocks as more companies adopt artificial-intelligence tools.