82692024-01-14 07:51:54MagyarKendeSZLGBináris fa magassága (50 pont)cpp17Accepted 50/5030ms4672 KiB
#include <bits/stdc++.h>
#define speed cin.tie(0); ios::sync_with_stdio(0)
using namespace std;

vector<int> heightS, cache;
int hs;

int height(int node) {
    if (node * 2 + 1 >= hs) {
        cache[node] = 0;
        return 0;
    }

    if (cache[node] == -1) {
        cache[node] = max(
            height(node * 2) + heightS[node * 2],
            height(node * 2 + 1) + heightS[node * 2 + 1]
        );
    }

    return cache[node];
}

int main() {
    speed;

    int N, M;
    cin >> N >> M;

    hs = (1 << N);

    heightS.assign(hs, 1);
    cache.assign(hs, -1);
    heightS[0] = 0;
    cache[0] = 0;

    while (M--) {
        int C, H;
        cin >> C >> H;
        heightS[C] = H;

        for (int i = C; i > 0; i /= 2) {
            cache[i] = -1;
        }

        cout << height(1) << '\n';
    }
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1892 KiB
2Accepted0/026ms3080 KiB
3Accepted2/23ms2292 KiB
4Accepted2/23ms2512 KiB
5Accepted2/23ms2752 KiB
6Accepted2/23ms2832 KiB
7Accepted3/33ms2932 KiB
8Accepted3/33ms2824 KiB
9Accepted3/33ms2952 KiB
10Accepted3/33ms3040 KiB
11Accepted2/230ms3984 KiB
12Accepted2/230ms3992 KiB
13Accepted2/230ms3984 KiB
14Accepted2/230ms4184 KiB
15Accepted2/229ms4228 KiB
16Accepted2/226ms4224 KiB
17Accepted2/226ms4396 KiB
18Accepted2/226ms4412 KiB
19Accepted2/226ms4404 KiB
20Accepted3/327ms4424 KiB
21Accepted3/327ms4408 KiB
22Accepted3/327ms4484 KiB
23Accepted3/327ms4672 KiB