88132024-01-31 15:27:06KezdőBináris fa magassága (50 pont)python3Time limit exceeded 30/50572ms17896 KiB
from sys import stdin,stdout

def main():
    N,M = [int(i) for i in stdin.readline().split()]
    k = [2**i for i in range(N+1)]
    f = [0,0]+[1]*k[N]
    h = [0]*k[N-1] + [N-1]*k[N-1]
    hdb = {N-1:k[N-1]}
    u = k[N-1]
    s = [0]
    for i in range(1,N+1):
        s = s + [i]*k[i-1]
##    print(s)

    maxi = N-1
    for i in range(M):
        a,uj = [int(i) for i in stdin.readline().split()]
        b = uj-f[a]
        f[a] = uj
        le = N-s[a]
        maxiuj = N-1
        for i in range(a*k[le],a*k[le]+k[le]):
##            print(hdb)
            hdb[h[i]] -= 1
            if hdb[h[i]] == 0:
                del hdb[h[i]]
            h[i] += b
            if h[i] in hdb:
                hdb[h[i]] += 1
            else:
##                print(h[i],hdb)
                hdb[h[i]] = 1
            if h[i] > maxiuj:
                maxiuj = h[i]
        if maxiuj > maxi:
            maxi = maxiuj
        else:
            maxi = max(hdb)
        stdout.write(str(maxi)+'\n')
main()    
SubtaskSumTestVerdictTimeMemory
base30/50
1Accepted0/017ms11484 KiB
2Time limit exceeded0/0564ms7180 KiB
3Accepted2/220ms12136 KiB
4Accepted2/220ms12324 KiB
5Accepted2/220ms12504 KiB
6Accepted2/221ms12684 KiB
7Accepted3/325ms12708 KiB
8Accepted3/328ms12664 KiB
9Accepted3/335ms13032 KiB
10Accepted3/332ms13160 KiB
11Accepted2/2294ms17680 KiB
12Accepted2/2280ms17752 KiB
13Accepted2/2268ms17896 KiB
14Accepted2/2261ms17740 KiB
15Accepted2/2252ms17896 KiB
16Time limit exceeded0/2561ms8556 KiB
17Time limit exceeded0/2568ms8840 KiB
18Time limit exceeded0/2560ms9224 KiB
19Time limit exceeded0/2572ms8880 KiB
20Time limit exceeded0/3572ms9008 KiB
21Time limit exceeded0/3568ms9220 KiB
22Time limit exceeded0/3563ms9076 KiB
23Time limit exceeded0/3568ms9284 KiB