82482024-01-13 20:21:15sangerafBináris fa magassága (50 pont)cpp17Accepted 50/50130ms5128 KiB
#include<bits/stdc++.h>
using namespace std;

const int N = 70000;
vector<int> h(N, 1);
vector<int> maxi(N, 1);

int n;

void build(int v, int f){
    if(f>n) return;
    maxi[v] = n-f;
    build(2*v, f+1);
    build(2*v+1, f+1);
}

int main(){
    cin >> n;
    int m; cin >> m;
    build(1, 1);
    while(m--){
        int a, b; cin >> a >> b;
        h[a] = b;
        int x = a/2;
        while(x>=1){
            maxi[x] = max(maxi[2*x] + h[2*x], maxi[2*x+1] + h[2*x+1]);
            x/=2;
        }
        cout << maxi[1] << endl;
    }
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms2776 KiB
2Accepted0/082ms2980 KiB
3Accepted2/26ms3144 KiB
4Accepted2/24ms3360 KiB
5Accepted2/24ms3568 KiB
6Accepted2/24ms3672 KiB
7Accepted3/34ms3872 KiB
8Accepted3/34ms3828 KiB
9Accepted3/34ms4140 KiB
10Accepted3/34ms4012 KiB
11Accepted2/287ms4336 KiB
12Accepted2/2107ms4432 KiB
13Accepted2/286ms4372 KiB
14Accepted2/286ms4696 KiB
15Accepted2/2115ms4652 KiB
16Accepted2/279ms4588 KiB
17Accepted2/2130ms4580 KiB
18Accepted2/281ms4584 KiB
19Accepted2/2128ms4924 KiB
20Accepted3/382ms4748 KiB
21Accepted3/382ms4920 KiB
22Accepted3/382ms5128 KiB
23Accepted3/379ms4984 KiB