83262024-01-14 18:06:58TuruTamasBináris fa magassága (50 pont)cpp17Elfogadva 50/5020ms6072 KiB
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
ifstream in_file("minta/be1.txt");
#define input in_file
#define INTHENAMEOFGOD
#else
#define input cin
#define INTHENAMEOFGOD \
    ios::sync_with_stdio(0); \
    cin.tie(0); \
    cout.tie(0);
#endif
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef array<ll, 2> all;

struct segment {
    ll len, val;
};

vector<segment> tree;
ll N, M, a, b;

void set_node(ll ind, ll val) {
    tree[ind-1].len = val;
    ll curr = ind/2;
    while (curr > 0) {
        tree[curr-1].val = max(
            tree[curr*2-1].len + tree[curr*2-1].val,
            tree[curr*2].len + tree[curr*2].val
        );
        curr /= 2;
    }
}

int main() {
    INTHENAMEOFGOD
    input >> N >> M;
    for (ll n = 0; n < N; n++) {
        for (ll i = 0; i < 1 << n; i++) {
            tree.push_back((segment) {
                .len = 1,
                .val = N-n-1,
            });
        }
    }
    for (ll m = 0; m < M; m++) {
        input >> a >> b;
        set_node(a, b);
        cout << tree[0].val << "\n";
    }

}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/03ms1888 KiB
2Elfogadva0/019ms4392 KiB
3Elfogadva2/23ms2408 KiB
4Elfogadva2/23ms2548 KiB
5Elfogadva2/23ms2764 KiB
6Elfogadva2/23ms2728 KiB
7Elfogadva3/33ms2872 KiB
8Elfogadva3/33ms2800 KiB
9Elfogadva3/33ms3080 KiB
10Elfogadva3/33ms3164 KiB
11Elfogadva2/219ms5248 KiB
12Elfogadva2/219ms5308 KiB
13Elfogadva2/219ms5528 KiB
14Elfogadva2/219ms5388 KiB
15Elfogadva2/219ms5520 KiB
16Elfogadva2/218ms5528 KiB
17Elfogadva2/218ms5524 KiB
18Elfogadva2/219ms5516 KiB
19Elfogadva2/218ms5644 KiB
20Elfogadva3/319ms5732 KiB
21Elfogadva3/320ms6072 KiB
22Elfogadva3/319ms5940 KiB
23Elfogadva3/319ms5944 KiB