Longitudinal decorrelation of anisotropic flows in heavy-ion collisions at the CERN Large Hadron Collider