125552024-12-22 21:21:15BucsMateBináris fa magassága (50 pont)cpp17Accepted 50/50114ms1336 KiB
#include <iostream>

using namespace std;

void setupBinTree(int binTree[], int edges[], int level, int N, int node)
{
    if(level >= N){
        return;
    }
    binTree[node] = N - level - 1;
    edges[node] = 1;
    setupBinTree(binTree, edges, level+1, N, 2*node);
    setupBinTree(binTree, edges, level+1, N, 2*node+1);
}

void update(int binTree[], int edges[], int node)
{
    if(node < 1){
        return;
    }
    binTree[node] = max(binTree[2*node] + edges[2*node], binTree[2*node+1] + edges[2*node+1]);
    update(binTree, edges, node/2);
}

int main()
{
    int binTree[100000] = {}, edges[100000] = {};
    int N, M, val, tempNode;
    cin >> N >> M;
    setupBinTree(binTree, edges, 0, N, 1);

    for(int i = 0; i < M; i++){
        cin >> tempNode >> val;
        edges[tempNode] = val;
        if(tempNode%2 == 0){
            update(binTree, edges, tempNode/2);
        }
        else{
            update(binTree, edges, tempNode/2);
        }
        cout << binTree[1] << endl;
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/02ms1268 KiB
2Accepted0/0101ms1336 KiB
3Accepted2/24ms1080 KiB
4Accepted2/23ms1260 KiB
5Accepted2/23ms1080 KiB
6Accepted2/23ms1080 KiB
7Accepted3/33ms1080 KiB
8Accepted3/33ms1084 KiB
9Accepted3/33ms1080 KiB
10Accepted3/33ms1080 KiB
11Accepted2/2108ms1320 KiB
12Accepted2/2108ms1204 KiB
13Accepted2/2108ms1336 KiB
14Accepted2/2108ms1336 KiB
15Accepted2/2114ms1268 KiB
16Accepted2/2103ms1336 KiB
17Accepted2/2103ms1224 KiB
18Accepted2/2105ms1336 KiB
19Accepted2/2103ms1268 KiB
20Accepted3/3104ms1200 KiB
21Accepted3/3107ms1212 KiB
22Accepted3/3101ms1200 KiB
23Accepted3/3105ms1204 KiB