121412024-12-04 08:26:02dfehervariBinĂĄris fa magassĂĄga (50 pont)python3Time limit exceeded 20/50600ms6016 KiB
def gyerek(cs,z):
   csĂșcsok[cs]+=vĂĄltozĂĄs
   if z>0:
       gyerek(2*cs,z-1)
       gyerek(2*cs+1,z-1)
#1. BinĂĄris fa magassĂĄga
"""
befĂĄjl = open("be1.txt")
n,m=map(int,befĂĄjl.readline().split())
"""
n,m=map(int,input().split())
#print(n,m)
#csĂșcsok feltöltĂ©se
utak =[0,0] #Az adott csĂșcsba a szĂŒlƑtƑl vezetƑ Ășt hossza
csĂșcsok = [0,0] #Az adott csĂșcsba a gyökĂ©rtƑl vezetƑ Ășt hossza
for k in range(1,n):
    for j in range(2**k):
        csĂșcsok.append(k)
        utak.append(1)
#print(csĂșcsok)
db = len(csĂșcsok)
for i in range(m):
    """
    cs, h = map(int,befĂĄjl.readline().split())
    """
    cs, h = map(int,input().split())
    #print(cs,h)
    #Kell, hogy a csĂșcs hĂĄnyadik szinten van
    k = 1
    while (cs//(2**k)) != 0:
        k=k+1
    vĂĄltozĂĄs = h - utak[cs]
    utak[cs]=h
    gyerek(cs,n-k) #Ide kell betenni,hogy hĂĄny szint van hĂĄtra
    #print(csĂșcsok)
    print(max(csĂșcsok))
"""
befĂĄjl.close()
"""
SubtaskSumTestVerdictTimeMemory
base20/50
1Accepted0/016ms3128 KiB
2Time limit exceeded0/0587ms5500 KiB
3Accepted2/221ms2924 KiB
4Accepted2/223ms3128 KiB
5Accepted2/224ms3108 KiB
6Accepted2/221ms3156 KiB
7Accepted3/324ms3088 KiB
8Accepted3/328ms3128 KiB
9Accepted3/332ms2968 KiB
10Accepted3/332ms3164 KiB
11Time limit exceeded0/2586ms4248 KiB
12Time limit exceeded0/2600ms4272 KiB
13Time limit exceeded0/2600ms4228 KiB
14Time limit exceeded0/2583ms4224 KiB
15Time limit exceeded0/2583ms4268 KiB
16Time limit exceeded0/2600ms5504 KiB
17Time limit exceeded0/2600ms5084 KiB
18Time limit exceeded0/2588ms6016 KiB
19Time limit exceeded0/2587ms5248 KiB
20Time limit exceeded0/3600ms4224 KiB
21Time limit exceeded0/3600ms4224 KiB
22Time limit exceeded0/3584ms4416 KiB
23Time limit exceeded0/3591ms4224 KiB