83422024-01-14 19:39:38bovizdbBináris fa magassága (50 pont)cpp17Accepted 50/5024ms8116 KiB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define endl "\n"
#define pll pair<ll, ll>
#define fs first
#define sc second
#define vll vector<ll>
#define v2d vector<vector<ll>>
#define vpll vector<pll>
#define qll queue<ll>
#define stll stack<ll>
#define sll set<ll>
#define mll map<ll, ll>

/* ll n, m;
vector<pll> v;
vector<vector<pll>> g;

ll len(ll p)
{
    if (g[p].size() == 0) return 0;
    return max(len(g[p][0].fs) + g[p][0].sc, len(g[p][1].fs) + g[p][1].sc);
}

void solve()
{
    cin >> n >> m;
    v.resize(pow(2, n)-1);
    v[0] = {-1, -1};
    for (ll i = 1; i < n; i++)
    {
        for (ll j = pow(2, i); j < pow(2, i+1); j++)
        {
            v[j-1] = {pow(2, i-1)+(j % (ll) {pow(2, i)})/2-1, 1};
        }
    }
    g.resize(v.size());
    for (ll i = 1; i < g.size(); i++)
    {
        g[v[i].fs].push_back({i, 1});
    }
    for (ll i = 0; i < m; i++)
    {
        ll in1, in2;
        cin >> in1 >> in2;
        if (g[v[in1-1].fs][0].fs == in1-1)
        {
            g[v[in1-1].fs][0].sc = in2;
        }
        else
        {
            g[v[in1-1].fs][1].sc = in2;
        }
        v[in1-1].sc = in2;
        cout << len(0) << endl;
    }
} */


ll n, m;
vpll g;
vll s;

ll len(ll p)
{
    if (p == 1) return max(g[1].fs, g[1].sc);
    if (p%2 == 0) g[p/2].fs = max(g[p].fs, g[p].sc) + s[p];
    else g[p/2].sc = max(g[p].fs, g[p].sc) + s[p];
    return len(p/2);
}

void solve()
{
    cin >> n >> m;
    g.resize((1<<n));
    s.resize((1<<n), 1);
    for (ll i = 0; i < n; i++)
    {
        for (ll j = (1<<i); j < (1<<(i+1)); j++) g[j] = {n-i-1, n-i-1};
    }
    vll out(m);
    for (ll i = 0; i < m; i++)
    {
        ll in1, in2;
        cin >> in1 >> in2;
        ll dif = in2 - s[in1];
        s[in1] = in2;
        if (in1%2 == 0) g[in1/2].fs += dif;
        else g[in1/2].sc += dif;
        out[i] = len(in1);
    }
    for (ll i : out) cout << i << endl;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1828 KiB
2Accepted0/020ms6028 KiB
3Accepted2/23ms2352 KiB
4Accepted2/23ms2464 KiB
5Accepted2/23ms2684 KiB
6Accepted2/23ms3032 KiB
7Accepted3/33ms3144 KiB
8Accepted3/33ms3348 KiB
9Accepted3/33ms3332 KiB
10Accepted3/33ms3452 KiB
11Accepted2/224ms7396 KiB
12Accepted2/224ms7612 KiB
13Accepted2/224ms7604 KiB
14Accepted2/224ms7612 KiB
15Accepted2/224ms7496 KiB
16Accepted2/221ms7716 KiB
17Accepted2/221ms7704 KiB
18Accepted2/221ms7912 KiB
19Accepted2/221ms7776 KiB
20Accepted3/321ms7780 KiB
21Accepted3/321ms7856 KiB
22Accepted3/321ms8068 KiB
23Accepted3/321ms8116 KiB