85472024-01-21 18:50:33HorakZsofiBináris fa magassága (50 pont)cpp17Accepted 50/50120ms5300 KiB
#include <bits/stdc++.h>
using namespace std;
vector<int>plusz;
vector<int>maxi;
long long fuggveny(int x) {
	maxi[x]=max(maxi[2*x]+plusz[2*x], maxi[2*x+1]+plusz[2*x+1]);
	if(x==1){
		return maxi[1]+plusz[1];
	}else{
		return fuggveny(x/2);
	}
}
int main() {
	int n, t;
	cin>>n>>t;
	plusz.resize((1<<n), 0);
	maxi.resize((1<<n), 0);

	for(int i=2; i<(1<<n); i++){
		plusz[i]++;
		
			fuggveny(i/2);
		
	}
	for(int i=0; i<t; i++){
		int a, b;
		cin>>a>>b;
		plusz[a]=b;
		cout<<fuggveny(a/2)<<endl;
	}

}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms2020 KiB
2Accepted0/081ms3000 KiB
3Accepted2/24ms2292 KiB
4Accepted2/24ms2292 KiB
5Accepted2/24ms2420 KiB
6Accepted2/24ms2660 KiB
7Accepted3/34ms2844 KiB
8Accepted3/34ms2912 KiB
9Accepted3/34ms2888 KiB
10Accepted3/34ms3012 KiB
11Accepted2/2104ms4056 KiB
12Accepted2/287ms4268 KiB
13Accepted2/286ms4484 KiB
14Accepted2/2120ms4704 KiB
15Accepted2/286ms4780 KiB
16Accepted2/282ms4780 KiB
17Accepted2/282ms4780 KiB
18Accepted2/283ms4884 KiB
19Accepted2/282ms4880 KiB
20Accepted3/385ms4880 KiB
21Accepted3/382ms5004 KiB
22Accepted3/385ms5092 KiB
23Accepted3/382ms5300 KiB