96662024-02-23 20:20:12NagyLeoBináris fa magassága (50 pont)pypy3Accepted 50/50114ms95044 KiB
from sys import stdin, stdout
input=stdin.readline

def main2():
    N, M = map(int, input().split())
    # current_mods = {}

    corners_len = [0] * (2 ** N)
    elhossz = [1] * (2 ** N)
    # index=1
    # tav=N-1

    for i in range(N):
        ii = 2 ** i
        for j in range(ii):
            corners_len[ii + j] = N - i - 1

    for i in range(M):
        deepest = 0
        A, B = map(int, input().split())
        # current_mods[A] = B
        elhossz[A] = B
        curIndex = A
        while curIndex > 1:
            curIndex //= 2
            corners_len[curIndex] = max(corners_len[2 * curIndex] + elhossz[2 * curIndex],
                                        corners_len[2 * curIndex + 1] + elhossz[2 * curIndex + 1])
        stdout.write(str(corners_len[1])+"\n")


main2()
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/043ms76612 KiB
2Accepted0/092ms91628 KiB
3Accepted2/250ms80628 KiB
4Accepted2/267ms87936 KiB
5Accepted2/268ms88512 KiB
6Accepted2/268ms88760 KiB
7Accepted3/374ms89460 KiB
8Accepted3/372ms89532 KiB
9Accepted3/364ms89592 KiB
10Accepted3/364ms89688 KiB
11Accepted2/2100ms93864 KiB
12Accepted2/297ms93872 KiB
13Accepted2/2114ms94260 KiB
14Accepted2/2101ms94696 KiB
15Accepted2/2107ms95044 KiB
16Accepted2/294ms94816 KiB
17Accepted2/2101ms94912 KiB
18Accepted2/2101ms94900 KiB
19Accepted2/294ms94788 KiB
20Accepted3/3101ms94664 KiB
21Accepted3/392ms94772 KiB
22Accepted3/392ms94836 KiB
23Accepted3/3112ms94968 KiB