Doubt in(segment tree question)--->MAX QUERY-I

why i am getting tle in it?i am doing something like merge sort in segment tree building and then sort of binary search in segement node value on comlete overlapping. overall time complexity=O(NLOGN)+O(QLOGN*LOGN) nd N,Q<=1e5 so why is it giving me tle .pls help me out nd if my approach is incorrect suggest better approach.
link to my code is----https://ide.codingblocks.com/s/78345


i just initialised everything globally instead of paasing and AC .