# 1927 최소 힙
import sys
input = sys.stdin.readline
from queue import PriorityQueue
N = int(input())
q = PriorityQueue()
for _ in range(N):
num = int(input())
if num != 0:
q.put(num)
else:
if q.qsize() != 0:
print(q.get())
else:
print(0)
import sys
input = sys.stdin.readline
import heapq
N = int(input())
heap_q = []
for _ in range(N):
num = int(input())
if num != 0:
heapq.heappush(heap_q, num)
else:
if len(heap_q) != 0:
print(heapq.heappop(heap_q))
else:
print(0)
# 11286 절댓값 힙
import sys
input = sys.stdin.readline
from queue import PriorityQueue
q = PriorityQueue()
N = int(input())
for _ in range(N):
num = int(input())
if num == 0:
if q.qsize() != 0:
print(q.get()[1])
else:
print(0)
else:
q.put((abs(num), num))
import sys
input = sys.stdin.readline
import heapq
N = int(input())
heap_q = []
for _ in range(N):
num = int(input())
if num != 0:
heapq.heappush(heap_q, (abs(num), num))
else:
if len(heap_q) != 0:
print(heapq.heappop(heap_q)[1])
else:
print(0)
https://stackoverflow.com/questions/36991716/whats-the-difference-between-heapq-and-priorityqueue-in-python
https://slowsure.tistory.com/130
이 글의 설명에 따르면 PriorityQueue는 thread-safe 하고, heapq는 Non-safe 하다고 한다.
PriorityQueue는 thread-safe 를 확인하는 과정에서 시간이 추가로 걸린다.
Thread-safe는 멀티쓰레드 환경에서 쓰레드가 공유 자원에 동시에 접근해도 제대로 동작하도록 하는 것인데, 이에 관해서는 CS를 공부하며 따로 정리할 예정이다.