85712024-01-22 11:26:24tamasmarkBináris fa magassága (50 pont)cpp17Wrong answer 21/50143ms94928 KiB
// Binarisfa2.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

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

using namespace std;

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

void melysegi(int csp)
{
    if (csp * 2 + 1 <= pow(2, n) - 1 && csp * 2 <= pow(2, n) - 1)
    {
        x[csp].sum = max(x[csp * 2].sum + x[csp * 2].hossz, x[(csp * 2) + 1].sum + x[(csp * 2) + 1].hossz);
    }
    if (binaris.size() > 1)
    {
        if (binaris.back() == 1)
        {
            binaris.pop_back();
            melysegi((csp - 1) / 2);
        }
        else if (binaris.back() == 0)
        {
            binaris.pop_back();
            melysegi(csp / 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 i = 1; i <= m; ++i)
    {
        cin >> a >> b;
        x[a].hossz = b;
        atalakit(a);
        maxi = 0;
        melysegi(a);
        binaris.clear();
        cout << x[1].sum << "\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
base21/50
1Accepted0/03ms1832 KiB
2Wrong answer0/098ms92768 KiB
3Accepted2/23ms2244 KiB
4Accepted2/23ms2216 KiB
5Accepted2/23ms2376 KiB
6Accepted2/23ms2576 KiB
7Wrong answer0/33ms2796 KiB
8Accepted3/33ms2796 KiB
9Wrong answer0/34ms3144 KiB
10Wrong answer0/33ms3184 KiB
11Accepted2/2127ms93828 KiB
12Accepted2/2127ms93828 KiB
13Accepted2/2143ms94104 KiB
14Accepted2/2142ms93916 KiB
15Accepted2/2136ms93996 KiB
16Wrong answer0/2103ms94264 KiB
17Wrong answer0/2100ms94044 KiB
18Wrong answer0/2100ms94228 KiB
19Wrong answer0/2101ms94248 KiB
20Wrong answer0/3105ms94276 KiB
21Wrong answer0/3112ms94800 KiB
22Wrong answer0/3105ms94640 KiB
23Wrong answer0/3112ms94928 KiB