121422024-12-04 08:31:17dfehervariBinĂĄris fa magassĂĄga (50 pont)pypy3Time limit exceeded 20/50603ms29720 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/045ms19444 KiB
2Time limit exceeded0/0586ms29048 KiB
3Accepted2/278ms21880 KiB
4Accepted2/287ms22964 KiB
5Accepted2/2112ms24044 KiB
6Accepted2/292ms22508 KiB
7Accepted3/3112ms24180 KiB
8Accepted3/3136ms24296 KiB
9Accepted3/3101ms22984 KiB
10Accepted3/393ms23216 KiB
11Time limit exceeded0/2587ms28768 KiB
12Time limit exceeded0/2589ms28908 KiB
13Time limit exceeded0/2602ms28912 KiB
14Time limit exceeded0/2586ms28908 KiB
15Time limit exceeded0/2588ms28908 KiB
16Time limit exceeded0/2588ms29288 KiB
17Time limit exceeded0/2603ms29720 KiB
18Time limit exceeded0/2593ms29004 KiB
19Time limit exceeded0/2583ms29416 KiB
20Time limit exceeded0/3583ms29172 KiB
21Time limit exceeded0/3603ms28780 KiB
22Time limit exceeded0/3588ms28908 KiB
23Time limit exceeded0/3592ms28904 KiB