98582024-03-12 15:54:33VargusBináris fa magassága (50 pont)cpp17Wrong answer 0/503ms4116 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;
    beir >> 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)
    {
        beir >> 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
base0/50
1Wrong answer0/03ms1800 KiB
2Wrong answer0/03ms1992 KiB
3Wrong answer0/23ms2260 KiB
4Wrong answer0/22ms2192 KiB
5Wrong answer0/23ms2420 KiB
6Wrong answer0/23ms2632 KiB
7Wrong answer0/32ms2720 KiB
8Wrong answer0/32ms2744 KiB
9Wrong answer0/33ms2944 KiB
10Wrong answer0/32ms3032 KiB
11Wrong answer0/22ms2928 KiB
12Wrong answer0/23ms3156 KiB
13Wrong answer0/23ms3408 KiB
14Wrong answer0/22ms3400 KiB
15Wrong answer0/22ms3652 KiB
16Wrong answer0/23ms3756 KiB
17Wrong answer0/23ms3692 KiB
18Wrong answer0/22ms3576 KiB
19Wrong answer0/23ms3572 KiB
20Wrong answer0/33ms3800 KiB
21Wrong answer0/33ms4060 KiB
22Wrong answer0/32ms3988 KiB
23Wrong answer0/33ms4116 KiB