85652024-01-22 07:19:40bzsofiaBináris fa magassága (50 pont)cpp14Runtime error 30/50238ms128776 KiB
// Proba.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
//#include <fstream>
#include <vector>
#include <queue>
#include <cmath>

#define ll long long

using namespace std;

//ifstream fin("fa.in");
//ofstream fout("fa.out");

struct adat {
    int tav;
    int eddigi=1;
    bool lat;
    vector <int> sz, vegek;
};

ll i, j, n, m, N, a, b, c, akt;
priority_queue <pair<int, int>> pr;
vector <adat> x;
vector <ll> v;
queue <ll> s;

void mely(int akt)
{
    if (x[akt].sz.empty())
    {
        x[akt].vegek.push_back(akt);
        x[akt].tav = n - 1;
    }else for (auto& e : x[akt].sz)
    {
        if (!x[e].lat)
        {
            x[e].lat = 1;
           
            mely(e);

            for (auto& a : x[e].vegek)
            {
                x[akt].vegek.push_back(a);
            }
        }
    }
}

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

    cin >> n >> m;
   
    N = pow(2, n) - 1;
    x.resize(N+1);
    
    for (i = 1; i <= pow(2, n-1) - 1; ++i)
    {
        x[i].sz.push_back(i * 2);
        x[i].sz.push_back(i * 2 + 1);
    }

    x[1].lat = 1;
    mely(1);
    
    for (i = 1; i <= m; ++i)
    {
        cin >> a >> b;
        
        c = b;
        b=b-x[a].eddigi;
        x[a].eddigi = c;

        for (auto& e : x[a].vegek)
        {
            x[e].tav += b;
            pr.push({ x[e].tav, e });
        }

        while (x[pr.top().second].tav != pr.top().first)
        {
            pr.pop();
        }
        
        cout << pr.top().first << "\n";
    }

    return 0;
}

// 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
base30/50
1Accepted0/03ms1824 KiB
2Runtime error0/0217ms128776 KiB
3Accepted2/23ms2532 KiB
4Accepted2/23ms2380 KiB
5Accepted2/23ms2720 KiB
6Accepted2/23ms2916 KiB
7Accepted3/33ms3096 KiB
8Accepted3/34ms3348 KiB
9Accepted3/34ms3996 KiB
10Accepted3/34ms3588 KiB
11Accepted2/248ms21768 KiB
12Accepted2/245ms21760 KiB
13Accepted2/246ms21756 KiB
14Accepted2/246ms21784 KiB
15Accepted2/243ms21480 KiB
16Runtime error0/2195ms127292 KiB
17Runtime error0/2201ms127048 KiB
18Runtime error0/2212ms126884 KiB
19Runtime error0/2194ms126892 KiB
20Runtime error0/3238ms126868 KiB
21Runtime error0/3217ms126628 KiB
22Runtime error0/3233ms126388 KiB
23Runtime error0/3215ms126396 KiB