135772025-01-08 10:11:34RRoliBináris fa magassága (50 pont)cpp17Accepted 50/50118ms1076 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n, m, hossz[65536], maxi[65536];
	cin >> n >> m;

	hossz[1] = 0;
	maxi[1] = n-1;
	for(int i = 2; i < pow(2, n); i++) {
		hossz[i] = 1;
		maxi[i] = n-int(log2(i))-1;
	}

	for(int i = 0; i < m; i++) {
		int cs, h;
		cin >> cs >> h;
		hossz[cs] = h;
		int apa = cs/2;
		while(apa >= 1) {
			maxi[apa] = max(hossz[2*apa]+maxi[2*apa], hossz[2*apa+1]+maxi[2*apa+1]);
			apa /= 2;
		}
		cout << maxi[1] << '\n';
	}

	return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms316 KiB
2Accepted0/0105ms1076 KiB
3Accepted2/23ms316 KiB
4Accepted2/23ms316 KiB
5Accepted2/23ms316 KiB
6Accepted2/23ms316 KiB
7Accepted3/33ms332 KiB
8Accepted3/33ms316 KiB
9Accepted3/33ms316 KiB
10Accepted3/33ms316 KiB
11Accepted2/2118ms856 KiB
12Accepted2/2112ms924 KiB
13Accepted2/2118ms976 KiB
14Accepted2/2108ms1076 KiB
15Accepted2/2115ms1076 KiB
16Accepted2/2112ms1044 KiB
17Accepted2/2108ms964 KiB
18Accepted2/2103ms1076 KiB
19Accepted2/2114ms1076 KiB
20Accepted3/3109ms1076 KiB
21Accepted3/3112ms944 KiB
22Accepted3/3104ms1076 KiB
23Accepted3/3100ms1076 KiB