118772024-11-13 18:57:2942Bináris fa magassága (50 pont)pypy3Accepted 50/50119ms25228 KiB
# O(2^N+M*N)
from sys import stdin, stdout
input=stdin.readline

N,M=[int(x) for x in input().split()]
cur=[-1,N-1]
for i in range(N-1):cur+=[N-2-i]*2**(i+1)
elh=[-1]+[1]*(2**N-1)
for i in range(M):
 a,b=[int(x) for x in input().split()]
 elh[a]=b
 while a>1:
  a//=2
  cur[a]=max(cur[2*a]+elh[2*a],cur[2*a+1]+elh[2*a+1])
 print(cur[1])
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/043ms19476 KiB
2Accepted0/0100ms25012 KiB
3Accepted2/259ms21392 KiB
4Accepted2/271ms21744 KiB
5Accepted2/286ms21840 KiB
6Accepted2/274ms22476 KiB
7Accepted3/371ms22232 KiB
8Accepted3/371ms22208 KiB
9Accepted3/364ms22076 KiB
10Accepted3/383ms21988 KiB
11Accepted2/2104ms25064 KiB
12Accepted2/2119ms24808 KiB
13Accepted2/2116ms25032 KiB
14Accepted2/2107ms25060 KiB
15Accepted2/2108ms25228 KiB
16Accepted2/2109ms25060 KiB
17Accepted2/298ms25028 KiB
18Accepted2/2114ms24956 KiB
19Accepted2/298ms24848 KiB
20Accepted3/3116ms24548 KiB
21Accepted3/397ms24808 KiB
22Accepted3/3108ms24888 KiB
23Accepted3/398ms24964 KiB