Efficient calculation of exact exchange and RPA correlation energies in the adiabatic-connection fluctuation-dissipation theory