192722025-12-03 15:57:07szabelrBináris fa magassága (50 pont)cpp17Accepted 50/5097ms1076 KiB
#include <iostream>
#include <cmath>

using namespace std;
int check(int x, int dist[], int best[])
{
    while (x > 0)
    {
        best[x] = max(dist[2 * x] + best[x * 2], dist[2 * x + 1] + best[x * 2 + 1]);

        x = x / 2;
    }
    return best[1];
}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int dist[65537]{ 1 };
    int best[65537];
    int n, m;
    cin >> n >> m;
    int i = 1;
    int x = n - 1;
    int a = 1;
    int z = pow(2, n);
    while (i < z)
    {
        if (i == pow(2, a))
        {
            x--;
            a++;
        }

        best[i] = x;
        i++;
    }
    for (int i = 0; i < pow(2, n); i++)
    {
        dist[i] = 1;
    }
    int b, c;
    for (int i = 0; i < m; i++)
    {
        cin >> b >> c;
        dist[b] = c;
        cout << check(b / 2, dist, best) << endl;
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/02ms564 KiB
2Accepted0/085ms964 KiB
3Accepted2/23ms564 KiB
4Accepted2/23ms752 KiB
5Accepted2/23ms564 KiB
6Accepted2/23ms564 KiB
7Accepted3/33ms568 KiB
8Accepted3/33ms748 KiB
9Accepted3/33ms564 KiB
10Accepted3/33ms564 KiB
11Accepted2/293ms1076 KiB
12Accepted2/294ms976 KiB
13Accepted2/296ms1016 KiB
14Accepted2/286ms1076 KiB
15Accepted2/296ms1076 KiB
16Accepted2/293ms1024 KiB
17Accepted2/296ms1076 KiB
18Accepted2/283ms1076 KiB
19Accepted2/292ms952 KiB
20Accepted3/390ms1032 KiB
21Accepted3/397ms956 KiB
22Accepted3/385ms1076 KiB
23Accepted3/379ms1076 KiB