98642024-03-13 15:41:26VargusBináris fa magassága (50 pont)cpp17Accepted 50/50131ms6380 KiB
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#define ll long long 
using namespace std;
ll n, elso, utol, m;
vector<ll>x, st, stati;

void hossz(ll csp)
{
    if (csp >= elso)
    {
        st[csp] = x[csp];
        return;
    }

    hossz(2 * csp);
    hossz(2 * csp + 1);
    st[csp] = max(st[2 * csp], st[2 * csp + 1]) + x[csp];
}
deque<ll>v;
void friss(int csp, int i, int a, int el)
{
    if (csp == a)
    {
        st[csp] -= el;
        st[csp] += x[a];
        return;
    }
    if (v[i] == 1)friss(2 * csp + 1, i + 1, a, el);
    else friss(2 * csp, i + 1, a, el);
    st[csp] = max(st[2 * csp], st[2 * csp + 1]) + x[csp];
}

void kettes(ll a)
{
    while (a > 1)
    {
        v.push_front(a % 2);
        a = a / 2;
    }
}
int main()
{
    cin >> n >> m;
    elso = pow(2, n - 1);
    utol = pow(2, n) - 1;
    x.assign(utol + 1, 1);
    st.resize(utol + 1);
    x[1] = 0;
    hossz(1);
    for (int i = 1; i <= m; ++i)
    {
        ll a, b;
        cin >> a >> b;
        ll el = x[a];
        x[a] = b;
        v.clear();
        kettes(a);
        friss(1, 0, a, el);
        cout << st[1] << "\n";
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1808 KiB
2Accepted0/086ms4076 KiB
3Accepted2/24ms2328 KiB
4Accepted2/24ms2560 KiB
5Accepted2/24ms2652 KiB
6Accepted2/24ms2988 KiB
7Accepted3/34ms3128 KiB
8Accepted3/34ms3364 KiB
9Accepted3/34ms3576 KiB
10Accepted3/34ms3632 KiB
11Accepted2/296ms5492 KiB
12Accepted2/294ms5460 KiB
13Accepted2/2130ms5548 KiB
14Accepted2/2131ms5604 KiB
15Accepted2/297ms5672 KiB
16Accepted2/2112ms5796 KiB
17Accepted2/286ms5896 KiB
18Accepted2/2119ms6012 KiB
19Accepted2/2118ms5980 KiB
20Accepted3/3129ms6204 KiB
21Accepted3/3130ms6284 KiB
22Accepted3/387ms6380 KiB
23Accepted3/389ms6376 KiB