83262024-01-14 18:06:58TuruTamasBináris fa magassága (50 pont)cpp17Accepted 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";
    }

}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1888 KiB
2Accepted0/019ms4392 KiB
3Accepted2/23ms2408 KiB
4Accepted2/23ms2548 KiB
5Accepted2/23ms2764 KiB
6Accepted2/23ms2728 KiB
7Accepted3/33ms2872 KiB
8Accepted3/33ms2800 KiB
9Accepted3/33ms3080 KiB
10Accepted3/33ms3164 KiB
11Accepted2/219ms5248 KiB
12Accepted2/219ms5308 KiB
13Accepted2/219ms5528 KiB
14Accepted2/219ms5388 KiB
15Accepted2/219ms5520 KiB
16Accepted2/218ms5528 KiB
17Accepted2/218ms5524 KiB
18Accepted2/219ms5516 KiB
19Accepted2/218ms5644 KiB
20Accepted3/319ms5732 KiB
21Accepted3/320ms6072 KiB
22Accepted3/319ms5940 KiB
23Accepted3/319ms5944 KiB