92622024-02-19 14:07:45petergalambosBináris fa magassága (50 pont)python3Time limit exceeded 20/50587ms16800 KiB
from sys import stdin, stdout
def main():
    N, M = [int(i) for i in stdin.readline().split()]
    H = [N]
    E = [1]*(2**N)
    x = 1
    for i in range(N):
        H = H+[N-i-1]*x
        x *= 2
    
    for i in range(M):
        x,y = [int(i) for i in input().split()]
        E[x] = y
        while x//2 != 0:
            if x%2 == 0:
                if E[x]+H[x] > E[x+1]+H[x+1]:
                    H[x//2] = E[x]+H[x]
                else:
                    H[x//2] = E[x+1]+H[x+1]
            else:
                if E[x]+H[x] > E[x-1]+H[x-1]:
                    H[x//2] = E[x]+H[x]
                else:
                    H[x//2] = E[x-1]+H[x-1]
            x = x//2
        print(H[1])
    
##    stdout.write(str(max(H))+'\n')

main()
SubtaskSumTestVerdictTimeMemory
base20/50
1Accepted0/018ms11296 KiB
2Time limit exceeded0/0569ms14708 KiB
3Accepted2/224ms11708 KiB
4Accepted2/224ms11920 KiB
5Accepted2/225ms12184 KiB
6Accepted2/225ms11912 KiB
7Accepted3/325ms12316 KiB
8Accepted3/325ms12588 KiB
9Accepted3/327ms12712 KiB
10Accepted3/326ms13044 KiB
11Time limit exceeded0/2560ms6876 KiB
12Time limit exceeded0/2563ms6916 KiB
13Time limit exceeded0/2575ms7156 KiB
14Time limit exceeded0/2564ms7220 KiB
15Time limit exceeded0/2587ms7428 KiB
16Time limit exceeded0/2535ms7696 KiB
17Time limit exceeded0/2555ms16704 KiB
18Time limit exceeded0/2546ms7960 KiB
19Time limit exceeded0/2552ms16800 KiB
20Time limit exceeded0/3568ms7812 KiB
21Time limit exceeded0/3568ms7644 KiB
22Time limit exceeded0/3550ms7544 KiB
23Time limit exceeded0/3572ms7608 KiB