You are viewing a single comment's thread. Return to all comments →
Python
import heapq Q = int(input()) heap = [] for _ in range(Q): q = input().split() if q[0] == '1': heapq.heappush(heap, int(q[1])) elif q[0] == '2': ind = heap.index(int(q[1])) heap[ind] = heap[-1] heap.pop() if heap: heapq._siftup(heap, min(ind, len(heap)-1)) else: print(heap[0])
Seems like cookies are disabled on this browser, please enable them to open this website
QHEAP1
You are viewing a single comment's thread. Return to all comments →
Python