how to handles query in Hussain Set Question?

my idea is to use priority queue and divide the max each time by 2 and push it back manually ,please suggest me how to handle queries? what is your approach?