92302024-02-19 09:09:54KezdőBináris fa magassága (50 pont)python3Time limit exceeded 40/50559ms15840 KiB
from sys import stdin

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

    for i in range(M):
        cs,x = [int(i) for i in stdin.readline().split()]
        h[cs] = x
        while cs > 1:
            c = cs//2
            c2 = c*2
            if cs < k:
                a[c] = max(h[c2]+a[c2], h[c2+1]+a[c2+1])
            else:
                a[c] = max(h[c2], h[c2+1])
            cs = c
        print(a[1])

main()
SubtaskSumTestVerdictTimeMemory
base40/50
1Accepted0/018ms11172 KiB
2Accepted0/0344ms13768 KiB
3Accepted2/219ms11872 KiB
4Accepted2/219ms12396 KiB
5Accepted2/221ms12660 KiB
6Accepted2/220ms12584 KiB
7Accepted3/320ms13128 KiB
8Accepted3/321ms13264 KiB
9Accepted3/321ms13232 KiB
10Accepted3/321ms13436 KiB
11Time limit exceeded0/2537ms15056 KiB
12Time limit exceeded0/2544ms15180 KiB
13Time limit exceeded0/2540ms15592 KiB
14Time limit exceeded0/2541ms15580 KiB
15Time limit exceeded0/2559ms6940 KiB
16Accepted2/2345ms15732 KiB
17Accepted2/2347ms15700 KiB
18Accepted2/2349ms15456 KiB
19Accepted2/2349ms15756 KiB
20Accepted3/3382ms15716 KiB
21Accepted3/3386ms15832 KiB
22Accepted3/3386ms15764 KiB
23Accepted3/3379ms15840 KiB