Mechanisms of nonthermal destruction of the superconducting state and melting of the charge-density-wave state by femtosecond laser pulses