83412024-01-14 19:31:38bovizdbBináris fa magassága (50 pont)cpp17Wrong answer 2/5024ms7380 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/2].fs, max(g[p].fs, g[p].sc) + s[p]);
    else g[p/2].sc = max(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
base2/50
1Accepted0/03ms1832 KiB
2Wrong answer0/020ms6020 KiB
3Accepted2/23ms2240 KiB
4Wrong answer0/23ms2460 KiB
5Wrong answer0/23ms2672 KiB
6Wrong answer0/23ms2772 KiB
7Wrong answer0/33ms2852 KiB
8Wrong answer0/33ms3128 KiB
9Wrong answer0/33ms3008 KiB
10Wrong answer0/33ms3008 KiB
11Wrong answer0/224ms6952 KiB
12Wrong answer0/224ms7172 KiB
13Wrong answer0/224ms7080 KiB
14Wrong answer0/224ms7140 KiB
15Wrong answer0/224ms7172 KiB
16Wrong answer0/220ms7180 KiB
17Wrong answer0/221ms7152 KiB
18Wrong answer0/220ms7208 KiB
19Wrong answer0/220ms7344 KiB
20Wrong answer0/321ms7356 KiB
21Wrong answer0/320ms7352 KiB
22Wrong answer0/321ms7364 KiB
23Wrong answer0/320ms7380 KiB