Help needed

in the codechef question of GIVEAWAY Problem - CodeChef 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 hfsNLf - Online C++0x Compiler & Debugging Tool - Ideone.com