Magnetic diffusion and interaction effects on ultrahigh energy cosmic rays: Protons and nuclei