Spin and charge fluctuations in cuprate superconductors studied with resonant inelastic x-ray scattering