A very nice problem solved using treap: https://stackoverflow.com/questions/79751600/solve-cses-moun...