84962024-01-19 10:55:11tamasmarkBináris fa magassága (50 pont)cpp17Time limit exceeded 20/50603ms48748 KiB
// Binarisfa2.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <deque>
#include <cmath>

using namespace std;

struct adat {
    int ertek, hossz=1;
    deque<int>bin;
};
deque<int>binaris;
deque<adat>x;
int a, b,maxi,db,n,m;
void atalakit(int a)
{
    while (a > 0)
    {
        x[b].bin.push_back(a % 2);
        a = a / 2;
    }
}

void melysegi(int csp)
{
    //db += x[csp].hossz;
    /*if (binaris.back() == 0 && binaris.size()>1)
    {
        binaris.pop_back();
        melysegi(csp / 2);
    }
    else if (binaris.back() == 1&&binaris.size()>1)
    {
        binaris.pop_back();
        melysegi((csp - 1) / 2);
    }*/
    a = csp;
    for (auto& e : x[csp].bin)
    {
        if (e == 1)
        {
            
            db += x[a].hossz;
            a = (a - 1) / 2;
        }
        else if (e == 0)
        {
            
            db += x[a].hossz;
            a = a / 2;
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    x.resize(pow(2, n));   
    for (int j = pow(2, n - 1); j <= pow(2, n) - 1; ++j)
    {
        b = j;
        atalakit(j);
    }

    for (int i = 1; i <= m; ++i)
    {
        cin >> a >> b;
        x[a].hossz = b;
        maxi = 0;
        for (int j = pow(2, n - 1); j <= pow(2, n) - 1; ++j)
        {
            db= -1;
            melysegi(j);
            if (maxi < db) maxi = db;
        }

        cout << maxi << "\n";
    }
    return 0;
}
/*
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
base20/50
1Accepted0/03ms1704 KiB
2Time limit exceeded0/0603ms46076 KiB
3Accepted2/23ms2092 KiB
4Accepted2/23ms2316 KiB
5Accepted2/24ms2700 KiB
6Accepted2/23ms2756 KiB
7Accepted3/34ms3124 KiB
8Accepted3/38ms3120 KiB
9Accepted3/314ms3476 KiB
10Accepted3/314ms3744 KiB
11Time limit exceeded0/2558ms47644 KiB
12Time limit exceeded0/2569ms47812 KiB
13Time limit exceeded0/2564ms47748 KiB
14Time limit exceeded0/2556ms47664 KiB
15Time limit exceeded0/2561ms47984 KiB
16Time limit exceeded0/2546ms47980 KiB
17Time limit exceeded0/2550ms48056 KiB
18Time limit exceeded0/2574ms48344 KiB
19Time limit exceeded0/2550ms48300 KiB
20Time limit exceeded0/3569ms48508 KiB
21Time limit exceeded0/3569ms48452 KiB
22Time limit exceeded0/3554ms48364 KiB
23Time limit exceeded0/3555ms48748 KiB