132722025-01-07 11:36:17gyjazminBináris fa magassága (50 pont)cpp17Time limit exceeded 20/50600ms1016 KiB
#include <vector>
#include <iostream>
#include <cmath>
using namespace std;
int n, m,maxi;
vector<int> f;
vector<int> sz;
void szamol(int k,int s) {
    sz[k] = s + f[k];
    if (k * 2 < pow(2, n)) {
        szamol(k * 2, s+ f[k]);
        szamol(k * 2 + 1, s + f[k]);
    }
}
void ujraepit(int k, int ks) {
    sz[k] += ks;
    if (k * 2 < pow(2, n)) {
        ujraepit(k * 2, ks);
        ujraepit(k * 2 + 1, ks);
    }
}
int main()
{
    cin >> n >> m;
    f.resize(pow(2, n), 1);
    sz.resize(pow(2, n));
    maxi = n-1;
    szamol(2, 0);
    szamol(3, 0);
    for (int i = 0; i < m; i++) {
        int cs = 0, h = 0;
        cin >> cs >> h;
        int ks = h - f[cs]; 
        f[cs] = h;
        ujraepit(cs, ks);
        for (int i = pow(2, n-1); i < pow(2, n); i++) {
            if (sz[i] > maxi) maxi = sz[i];
        }
        cout << maxi << endl;
        maxi = n - 1;
    }
}
SubtaskSumTestVerdictTimeMemory
base20/50
1Accepted0/01ms316 KiB
2Time limit exceeded0/0586ms820 KiB
3Accepted2/23ms508 KiB
4Accepted2/23ms316 KiB
5Accepted2/23ms500 KiB
6Accepted2/23ms316 KiB
7Accepted3/34ms316 KiB
8Accepted3/34ms316 KiB
9Accepted3/38ms316 KiB
10Accepted3/38ms316 KiB
11Time limit exceeded0/2600ms820 KiB
12Time limit exceeded0/2600ms820 KiB
13Time limit exceeded0/2600ms928 KiB
14Time limit exceeded0/2582ms820 KiB
15Time limit exceeded0/2583ms1016 KiB
16Time limit exceeded0/2584ms820 KiB
17Time limit exceeded0/2600ms824 KiB
18Time limit exceeded0/2583ms820 KiB
19Time limit exceeded0/2587ms820 KiB
20Time limit exceeded0/3587ms820 KiB
21Time limit exceeded0/3600ms824 KiB
22Time limit exceeded0/3583ms820 KiB
23Time limit exceeded0/3575ms820 KiB