Last active
March 14, 2026 09:41
-
-
Save maehrm/f521a0e26a0dded48b3220f5e751388c to your computer and use it in GitHub Desktop.
E - Sorting Queries https://atcoder.jp/contests/abc217/tasks/abc217_e
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import heapq | |
| from collections import deque | |
| queA = deque() # まだソートされてない配列Aを表現 | |
| heapA = [] # ソート済みの配列Aを表現 | |
| Q = int(input()) | |
| for _ in range(Q): | |
| query = list(map(int, input().split())) | |
| if query[0] == 1: | |
| x = query[1] | |
| queA.append(x) | |
| elif query[0] == 2: | |
| if heapA: | |
| x = heapq.heappop(heapA) | |
| else: | |
| x = queA.popleft() | |
| print(x) | |
| else: | |
| while queA: | |
| x = queA.popleft() | |
| heapq.heappush(heapA, x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment