98632024-03-13 07:47:46VargusBináris fa magassága (50 pont)cpp17Runtime error 14/50128ms5732 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)
{
    
    if (csp >= n)
    {
        mag[csp] = x[csp];
        return;
    }
    v.pop_front();
    if (v.empty() || 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;
        ll j1 = j;
        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
base14/50
1Accepted0/03ms1808 KiB
2Runtime error0/03ms4156 KiB
3Accepted2/24ms2248 KiB
4Accepted2/24ms2428 KiB
5Runtime error0/23ms2612 KiB
6Runtime error0/23ms2616 KiB
7Runtime error0/33ms2480 KiB
8Runtime error0/33ms2616 KiB
9Runtime error0/33ms2740 KiB
10Runtime error0/33ms2996 KiB
11Accepted2/296ms4980 KiB
12Accepted2/2128ms5056 KiB
13Accepted2/2123ms5212 KiB
14Accepted2/296ms5324 KiB
15Accepted2/294ms5320 KiB
16Runtime error0/23ms5472 KiB
17Runtime error0/23ms5532 KiB
18Runtime error0/23ms5536 KiB
19Runtime error0/23ms5308 KiB
20Runtime error0/34ms5420 KiB
21Runtime error0/33ms5560 KiB
22Runtime error0/33ms5732 KiB
23Runtime error0/33ms5636 KiB