Help needed

help

#1

in the codechef question of https://www.codechef.com/problems/GIVEAWAY i used treap at every node of segment tree can anyone explain why its verdicting tle… it looks my treap is not working properly… here is link to my code https://ideone.com/hfsNLf