Cod sursa(job #2715048)

Utilizator 05_YohnE1 La5c01 05_Yohn Data 2 martie 2021 21:03:40
Problema Heapuri Scor 40
Compilator py Status done
Runda Arhiva educationala Marime 0.81 kb
import heapq

def search(v,x):
    a,b,m = 0, len(v), len(v) // 2
    while (a < b) :
        if (v[m] < x) :
            a,m = m+1, (1+b+m) // 2
        else :
            b, m = m, (a+m) //2
    return b

input = open("heapuri.in", "r")
output = open("heapuri.out","w")
v = {}
heap = []
i=1
operations = int(input.readline())

while(operations>0):
    op_type = input.readline().replace("\n","").split(" ")
    if(int(op_type[0])==1):
        x = int(op_type[1])
        v.update({i:x})
        heap.insert(search(heap,x),x)
        i += 1
    if(int(op_type[0])==2):
        x = int(op_type[1])
        heap.pop(search(heap,v[x]))
        v.pop(x)
    if(int(op_type[0])==3):
        output.write(str(heap[0]))
        output.write("\n")

    operations -=1

input.close()
output.close()