QHEAP1

  • + 0 comments

    Python. Possibly not the intended solution.

    import heapq
    
    q = int(input())
    heap = []
    deleted = set()
    for _ in range(q):
        line = input().split()
        command = line[0]
        if len(line) > 1:
            val = int(line[1])
        if command == "1":
            if val in deleted:
                deleted.remove(val)
            else:
                heapq.heappush(heap, val)
        elif command == "2":
            deleted.add(val)
        elif command == "3":
            x = heap[0]
            while x in deleted:
                heapq.heappop(heap)
                deleted.remove(x)
                x = heap[0]
            print(x)