92292024-02-19 08:33:37KezdőBináris fa magassága (50 pont)python3Time limit exceeded 40/50522ms16412 KiB
from sys import stdin,stdout

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+1):
        a = a + [N-i]*k
        k *= 2
    h = [1]*k

    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
            a[c] = max(h[c2]+a[c2], h[c2+1]+a[c2+1])
            cs = c
        print(a[1])

main()
SubtaskSumTestVerdictTimeMemory
base40/50
1Accepted0/017ms11060 KiB
2Accepted0/0331ms14116 KiB
3Accepted2/219ms12132 KiB
4Accepted2/219ms12168 KiB
5Accepted2/219ms12212 KiB
6Accepted2/220ms12244 KiB
7Accepted3/320ms12396 KiB
8Accepted3/320ms12548 KiB
9Accepted3/323ms12868 KiB
10Accepted3/323ms13080 KiB
11Time limit exceeded0/2522ms15440 KiB
12Time limit exceeded0/2518ms15812 KiB
13Time limit exceeded0/2518ms15800 KiB
14Time limit exceeded0/2521ms15756 KiB
15Time limit exceeded0/2521ms16036 KiB
16Accepted2/2333ms15872 KiB
17Accepted2/2337ms16000 KiB
18Accepted2/2335ms16324 KiB
19Accepted2/2335ms16260 KiB
20Accepted3/3368ms16412 KiB
21Accepted3/3368ms16376 KiB
22Accepted3/3370ms16192 KiB
23Accepted3/3363ms16304 KiB