85652024-01-22 07:19:40bzsofiaBináris fa magassága (50 pont)cpp14Futási hiba 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
RészfeladatÖsszpontTesztVerdiktIdőMemória
base30/50
1Elfogadva0/03ms1824 KiB
2Futási hiba0/0217ms128776 KiB
3Elfogadva2/23ms2532 KiB
4Elfogadva2/23ms2380 KiB
5Elfogadva2/23ms2720 KiB
6Elfogadva2/23ms2916 KiB
7Elfogadva3/33ms3096 KiB
8Elfogadva3/34ms3348 KiB
9Elfogadva3/34ms3996 KiB
10Elfogadva3/34ms3588 KiB
11Elfogadva2/248ms21768 KiB
12Elfogadva2/245ms21760 KiB
13Elfogadva2/246ms21756 KiB
14Elfogadva2/246ms21784 KiB
15Elfogadva2/243ms21480 KiB
16Futási hiba0/2195ms127292 KiB
17Futási hiba0/2201ms127048 KiB
18Futási hiba0/2212ms126884 KiB
19Futási hiba0/2194ms126892 KiB
20Futási hiba0/3238ms126868 KiB
21Futási hiba0/3217ms126628 KiB
22Futási hiba0/3233ms126388 KiB
23Futási hiba0/3215ms126396 KiB