98592024-03-12 15:55:53VargusBináris fa magassága (50 pont)cpp17Runtime error 12/5097ms5740 KiB
#include <iostream>
#include <algorithm>
#include <cmath>
// #include <fstream>
#include <queue>
#define ll long long

using namespace std;

// ifstream beir("fa.in");

vector <ll> mag, x;
deque <ll> v;

void magassag(ll csp, ll n)
{
    v.pop_front();
    if(csp >= n)
    {
        mag[csp] = x[csp];
        return;
    }
    if(v.front() == 0)
        magassag(2*csp, n);
    else
        magassag(2*csp+1, n);
    mag[csp] = max(mag[csp*2], mag[csp*2+1]) + x[csp];
}

int main()
{
    ll n, csp, k, j, g;
    cin >> n >> k;
    csp = pow(2, n) - 1;
    x.assign(csp+1, 1);
    mag.resize(csp+1);
    x[1] = 0;
    for(ll i=1; i<=k; ++i)
    {
        cin >> j >> g;
        x[j] = g;
        while(j)
        {
            v.push_front(j % 2);
            j /= 2;
        }
        magassag(1, pow(2, n-1));
        cout << mag[1] << endl;
        v.clear();
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base12/50
1Accepted0/03ms1816 KiB
2Runtime error0/03ms4204 KiB
3Accepted2/24ms2492 KiB
4Runtime error0/23ms2636 KiB
5Runtime error0/23ms2632 KiB
6Runtime error0/23ms2904 KiB
7Runtime error0/33ms2960 KiB
8Runtime error0/33ms2972 KiB
9Runtime error0/33ms3244 KiB
10Runtime error0/33ms3304 KiB
11Accepted2/297ms5208 KiB
12Accepted2/297ms5212 KiB
13Accepted2/297ms5208 KiB
14Accepted2/297ms5360 KiB
15Accepted2/297ms5392 KiB
16Runtime error0/23ms5584 KiB
17Runtime error0/23ms5480 KiB
18Runtime error0/23ms5592 KiB
19Runtime error0/23ms5476 KiB
20Runtime error0/33ms5480 KiB
21Runtime error0/34ms5720 KiB
22Runtime error0/33ms5620 KiB
23Runtime error0/34ms5740 KiB