98622024-03-12 16:37:26VargusBináris fa magassága (50 pont)cpp17Wrong answer 12/50136ms127880 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 || v.empty())
    {
        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);
    v.resize(pow(n, n));
    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/03ms1680 KiB
2Wrong answer0/0129ms3800 KiB
3Accepted2/24ms2152 KiB
4Wrong answer0/24ms2348 KiB
5Wrong answer0/24ms2568 KiB
6Wrong answer0/24ms2784 KiB
7Wrong answer0/34ms3760 KiB
8Wrong answer0/312ms16380 KiB
9Runtime error0/350ms127880 KiB
10Runtime error0/356ms127644 KiB
11Accepted2/2136ms5364 KiB
12Accepted2/297ms5464 KiB
13Accepted2/2129ms5840 KiB
14Accepted2/2100ms5680 KiB
15Accepted2/2125ms5564 KiB
16Wrong answer0/290ms5580 KiB
17Wrong answer0/287ms5688 KiB
18Wrong answer0/290ms5908 KiB
19Wrong answer0/2115ms5972 KiB
20Wrong answer0/390ms6064 KiB
21Wrong answer0/389ms6152 KiB
22Wrong answer0/390ms6052 KiB
23Wrong answer0/390ms6048 KiB