82542024-01-13 20:40:02szilBináris fa magassága (50 pont)cpp17Accepted 50/5035ms8984 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int MAXN = 200'001;

int t[2*MAXN], tleft[MAXN], tright[MAXN], lazy[MAXN], edge_weight[MAXN];

void push(int v) {
    if (lazy[v]) {
        t[v] += lazy[v];
        lazy[2*v] += lazy[v];
        lazy[2*v+1] += lazy[v];
        lazy[v] = 0;
    }
}

void dfs(int v, int tl, int tr, int depth) {
    tleft[v] = tl; tright[v] = tr;
    if (tl == tr) {
        t[v] = depth;
    } else {
        int tm = (tl + tr) / 2;
        dfs(2*v, tl, tm, depth+1);
        dfs(2*v+1, tm+1, tr, depth+1);
        t[v] = max(t[2*v], t[2*v+1]);
    }
}

void upd(int v, int tl, int tr, int l, int r, int val) {
    if (l > r) return;
    if (tl == l && tr == r) {
        lazy[v] += val;
        push(v);
    } else {
        push(v);
        int tm = (tl + tr) / 2;
        upd(2*v, tl, tm, l, min(r, tm), val);
        upd(2*v+1, tm+1, tr, max(l, tm+1), r, val);
        push(2*v);
        push(2*v+1);
        t[v] = max(t[2*v], t[2*v+1]);
    }
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    fill(edge_weight, edge_weight+MAXN, 1);
    int n, m; cin >> n >> m;
    int nodes = 1<<(n-1);
    dfs(1, 1, nodes, 0);
    while (m--) {
        int u, val; cin >> u >> val;
        int tmp = val;
        val = val-edge_weight[u];
        edge_weight[u] = tmp;
        upd(1, 1, nodes, tleft[u], tright[u], val);
        cout << t[1] << "\n";
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/04ms3728 KiB
2Accepted0/028ms6476 KiB
3Accepted2/23ms4200 KiB
4Accepted2/23ms4420 KiB
5Accepted2/24ms4540 KiB
6Accepted2/24ms4656 KiB
7Accepted3/34ms4964 KiB
8Accepted3/34ms5180 KiB
9Accepted3/34ms5540 KiB
10Accepted3/33ms5600 KiB
11Accepted2/235ms7932 KiB
12Accepted2/235ms8064 KiB
13Accepted2/235ms8016 KiB
14Accepted2/234ms8024 KiB
15Accepted2/234ms8076 KiB
16Accepted2/228ms8456 KiB
17Accepted2/228ms8436 KiB
18Accepted2/228ms8856 KiB
19Accepted2/228ms8768 KiB
20Accepted3/328ms8756 KiB
21Accepted3/328ms8984 KiB
22Accepted3/328ms8976 KiB
23Accepted3/328ms8884 KiB