87992024-01-31 09:02:09KezdőBináris fa magassága (50 pont)python3Time limit exceeded 30/50587ms17028 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]
##    print(f)

    def holvan(x):
        s = 1
        while x >= k[s]:
            s += 1
        return 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
        sor = holvan(a)
        le = N-sor
        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/018ms11536 KiB
2Time limit exceeded0/0573ms6324 KiB
3Accepted2/220ms12148 KiB
4Accepted2/220ms12548 KiB
5Accepted2/223ms12676 KiB
6Accepted2/223ms12668 KiB
7Accepted3/326ms12616 KiB
8Accepted3/328ms12928 KiB
9Accepted3/335ms13240 KiB
10Accepted3/334ms13248 KiB
11Accepted2/2365ms16476 KiB
12Accepted2/2352ms16492 KiB
13Accepted2/2342ms16592 KiB
14Accepted2/2335ms16704 KiB
15Accepted2/2326ms17028 KiB
16Time limit exceeded0/2569ms8344 KiB
17Time limit exceeded0/2566ms8208 KiB
18Time limit exceeded0/2563ms8472 KiB
19Time limit exceeded0/2587ms8440 KiB
20Time limit exceeded0/3583ms8444 KiB
21Time limit exceeded0/3587ms8564 KiB
22Time limit exceeded0/3568ms8600 KiB
23Time limit exceeded0/3575ms8956 KiB