TLE in EXUNC

Hi,
My solution for EXUNC keeps getting time limit exceeded and I’m at my wits end for this now. Could someone guide me in the right direction with this?
My logic was to keep track of the first element of each subarray in a set and to manipulate this set based on queries of type 1 and to fetch the greatest element from this set that is lesser than or equal to the input of query type 2.
Problem: https://www.codechef.com/LRNDSA03/problems/EXUNC/
Soln: https://www.codechef.com/viewsolution/39314160