-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7662_re.py
27 lines (26 loc) · 957 Bytes
/
7662_re.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import sys;read=sys.stdin.readline
import heapq
result=[]
for T in range(int(read())):
visited=[False]*1_000_001
minH,maxH=[],[]
for i in range(int(read())):
alpha, num = read().split()
if alpha == 'I':
heapq.heappush(minH,(int(num),i))
heapq.heappush(maxH,(-int(num),i))
visited[i]=True
elif num=='1':
while maxH and not visited[maxH[0][1]]:heapq.heappop(maxH)
if maxH:
visited[maxH[0][1]]=False
heapq.heappop(maxH)
else:
while minH and not visited[minH[0][1]]:heapq.heappop(minH)
if minH:
visited[minH[0][1]]=False
heapq.heappop(minH)
while minH and not visited[minH[0][1]]:heapq.heappop(minH)
while maxH and not visited[maxH[0][1]]:heapq.heappop(maxH)
result.append(f'{-maxH[0][0]} {minH[0][0]}'if maxH and minH else'EMPTY')
print('\n'.join(result))