214662026-01-13 09:41:44gkataBináris fa magassága (50 pont)cpp17Accepted 50/50103ms4192 KiB
// binaris_fa.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include<queue>
#include<cmath>
#define ll long long

using namespace std;

struct adat {
    int lat, tav, apa;
    vector<ll>sz;
};

vector<adat>x;
int n, m, i, a, b, k, l, p;

void fa(ll magassag)
{
    int j = pow(2, magassag - 1);
    for (int i = 0; i < j - 1; ++i)
    {
        x[i].sz.push_back(2 * i + 1);
        x[i].sz.push_back(2 * i + 2);
    }
    x[0].tav = magassag - 1;
    for (i = 1; i <= k - 2; ++i)
    {
        x[i].apa = 1;
        x[i].tav = x[(i - 1) / 2].tav - 1;
    }
}

void hossz(ll csp)
{
    l = x[csp * 2 + 1].apa + x[csp * 2 + 1].tav;
    p = x[csp * 2 + 2].apa + x[csp * 2 + 2].tav;
    if ((x[csp * 2 + 1].apa + x[csp * 2 + 1].tav) > (x[csp * 2 + 2].apa + x[csp * 2 + 2].tav)) x[csp].tav = x[csp * 2 + 1].apa + x[csp * 2 + 1].tav;
    else x[csp].tav = x[csp * 2 + 2].apa + x[csp * 2 + 2].tav;
    if (csp) hossz((csp - 1) / 2);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> m;

    k = pow(2, n);
    x.resize(k);

    fa(n);

    for (i = 1; i <= m; ++i)
    {
        cin >> a >> b;
        x[a - 1].apa = b;
        if (a % 2 == 0) hossz((a - 1) / 2);
        else hossz((a - 1) / 2 - 1);

        cout << x[0].tav << endl;
    }

}

/*
3 5
2 6
4 3
6 7
5 4
2 1
*/
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms316 KiB
2Accepted0/093ms4148 KiB
3Accepted2/23ms316 KiB
4Accepted2/23ms316 KiB
5Accepted2/23ms316 KiB
6Accepted2/23ms316 KiB
7Accepted3/33ms316 KiB
8Accepted3/33ms316 KiB
9Accepted3/33ms316 KiB
10Accepted3/33ms316 KiB
11Accepted2/2101ms4044 KiB
12Accepted2/2100ms4076 KiB
13Accepted2/2103ms4104 KiB
14Accepted2/293ms4148 KiB
15Accepted2/2100ms4064 KiB
16Accepted2/297ms4192 KiB
17Accepted2/2101ms4084 KiB
18Accepted2/290ms4148 KiB
19Accepted2/2101ms4144 KiB
20Accepted3/397ms4084 KiB
21Accepted3/394ms4056 KiB
22Accepted3/387ms4148 KiB
23Accepted3/385ms4092 KiB