classSolution: defleftmostBuildingQueries(self, heights: List[int], queries: List[List[int]]) -> List[int]: n=len(queries) hash={}#记录b对应的a和index for i inrange(n): a=min(queries[i]) b=max(queries[i]) if b notinhash: hash[b]=[] hash[b].append([a,i]) #记录右边单调递增 st=[] res=[-1]*n for i inrange(len(heights)-1,-1,-1): h=heights[i] while st and h>heights[st[-1]]: st.pop() st.append(i) if i inhash: b=i for a,index inhash[i]: if heights[b]>heights[a] or a==b: res[index]=b else: l,r=0,len(st)-1 while l<=r: mid=(l+r)//2 if heights[st[mid]]>heights[a]: l=mid+1 else: r=mid-1 if (l-1<0): res[index]=-1 else: res[index]=st[l-1] return res