92262024-02-18 23:37:23KezdőBináris fa magassága (50 pont)python3Time limit exceeded 40/50587ms16596 KiB
from sys import stdin,stdout

def main():
    N,M = [int(i) for i in stdin.readline().split()]
    t = 2**N
    a = [N]   # alatta levő "mélység"
    k = 1
    for i in range(1,N+1):
        a = a + [N-i]*k
        k *= 2
    h = [1]*2**N

    for i in range(M):
        cs,x = [int(i) for i in stdin.readline().split()]
        h[cs] = x
        while cs > 1:
            cs //= 2
            a[cs] = max(h[2*cs]+a[2*cs], h[2*cs+1]+a[2*cs+1])
        print(a[1])
    
main() 
SubtaskSumTestVerdictTimeMemory
base40/50
1Accepted0/017ms11476 KiB
2Accepted0/0370ms14268 KiB
3Accepted2/220ms12004 KiB
4Accepted2/219ms12324 KiB
5Accepted2/220ms12184 KiB
6Accepted2/219ms12496 KiB
7Accepted3/320ms12696 KiB
8Accepted3/321ms12588 KiB
9Accepted3/323ms12916 KiB
10Accepted3/323ms13068 KiB
11Time limit exceeded0/2552ms6928 KiB
12Time limit exceeded0/2556ms6988 KiB
13Time limit exceeded0/2587ms6796 KiB
14Time limit exceeded0/2575ms6784 KiB
15Time limit exceeded0/2587ms7108 KiB
16Accepted2/2370ms15916 KiB
17Accepted2/2372ms15832 KiB
18Accepted2/2367ms16156 KiB
19Accepted2/2368ms15896 KiB
20Accepted3/3411ms15864 KiB
21Accepted3/3409ms16336 KiB
22Accepted3/3414ms16528 KiB
23Accepted3/3409ms16596 KiB