84392024-01-16 10:11:10birozsBináris fa magassága (50 pont)python3Time limit exceeded 2/50600ms13200 KiB
N,M = map(int,input().split())
L = 2**(N-1)
mag = [N-1] * 2**(N-1)
lista = [1] * 2**N
aktmax = N-1
mo = []
for i in range(M):
    csucs,hossz = map(int,input().split())
    aktsor = 1
    while not (csucs > 2**(aktsor-1) and csucs < 2**(aktsor+1)):
        aktsor += 1
    aktsor += 1
    levelszam = 2**(N-aktsor)
    elsolevel = csucs * 2**(N-aktsor)
    valtozas = hossz - lista[csucs]
    lista[csucs] = hossz
    ittvan = False
    for i in range(elsolevel,elsolevel+levelszam):
        if valtozas > 0 and mag[i-L] == aktmax:
            ittvan = True
            aktmax = mag[i-L] + valtozas
        mag[i-L] += valtozas
    if ittvan:
        mo.append(aktmax)
        #print(aktmax)
    else:
        mo.append(max(mag))
        #print(max(mag))

for x in mo:
    print(x)

SubtaskSumTestVerdictTimeMemory
base2/50
1Accepted0/017ms11116 KiB
2Time limit exceeded0/0600ms5592 KiB
3Accepted2/221ms11752 KiB
4Wrong answer0/223ms12040 KiB
5Wrong answer0/224ms12532 KiB
6Wrong answer0/225ms12656 KiB
7Wrong answer0/328ms12672 KiB
8Wrong answer0/329ms12824 KiB
9Wrong answer0/335ms12868 KiB
10Wrong answer0/335ms13200 KiB
11Time limit exceeded0/2600ms6428 KiB
12Time limit exceeded0/2551ms6752 KiB
13Time limit exceeded0/2572ms6756 KiB
14Time limit exceeded0/2583ms6740 KiB
15Time limit exceeded0/2555ms6696 KiB
16Time limit exceeded0/2559ms7500 KiB
17Time limit exceeded0/2572ms7364 KiB
18Time limit exceeded0/2600ms7992 KiB
19Time limit exceeded0/2575ms7592 KiB
20Time limit exceeded0/3575ms7212 KiB
21Time limit exceeded0/3579ms7200 KiB
22Time limit exceeded0/3572ms7284 KiB
23Time limit exceeded0/3568ms7412 KiB