목차

이중 우선순위 큐

ps
링크acmicpc.net/…
출처BOJ
문제 번호7662
문제명이중 우선순위 큐
레벨골드 5
분류

우선순위큐

시간복잡도O(nlogn)
인풋사이즈n<=1,000,000
제출기록128892KB / 5644ms
최고기록3156ms
해결날짜2021/05/14

풀이

코드

"""Solution code for "BOJ 7662. 이중 우선순위 큐".

- Problem link: https://www.acmicpc.net/problem/7662
- Solution link: http://www.teferi.net/ps/problems/boj/7662
"""

import sys
from teflib import priorityqueue


def main():
    T = int(sys.stdin.readline())
    for _ in range(T):
        max_heap = priorityqueue.UpdatableHeap()
        min_heap = priorityqueue.UpdatableHeap()
        k = int(sys.stdin.readline())
        for _ in range(k):
            op, n = sys.stdin.readline().split()
            if op == 'I':
                num = int(n)
                max_heap.push(-num)
                min_heap.push(num)
            elif max_heap:
                if n == '1':
                    num = -max_heap.pop()
                    min_heap.delete(num)
                elif n == '-1':
                    num = min_heap.pop()
                    max_heap.delete(-num)
        if max_heap:
            print(-max_heap.top(), min_heap.top())
        else:
            print('EMPTY')


if __name__ == '__main__':
    main()