The Rio Olympics ended with a spectacular closing ceremony as Olympic flag goes to Tokyo as an official handover.