201982026-01-04 19:07:22hunzombiBináris fa magassága (50 pont)cpp17Time limit exceeded 20/50600ms1120 KiB
#include <bits/stdc++.h>
using namespace std;

/*

important property of binary trees
parent = floor_division(node)
*/

int fastPow(int a, int b) {
    if (b == 0) return 1;
    int ans = fastPow(a, b / 2);
    ans = ans * ans;
    if (b & 1) {
        return a * ans;
    }
    return ans;
}

int main()
{
    int n, m;
    cin >> n;
    cin >> m;

    n = fastPow(2, n);

    vector<int> val(n, 1), dp;

    for (int i=0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        val[u] = v;

        dp.assign(n, 0);

        for (int i = n - 1; i > 0; i--) {
            if (dp[i / 2] < dp[i] + val[i]) {
                dp[i / 2] = dp[i] + val[i];
            }
        }
        cout << dp[1] << '\n';
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base20/50
1Accepted0/01ms316 KiB
2Time limit exceeded0/0573ms820 KiB
3Accepted2/23ms508 KiB
4Accepted2/23ms316 KiB
5Accepted2/23ms316 KiB
6Accepted2/23ms508 KiB
7Accepted3/33ms316 KiB
8Accepted3/33ms316 KiB
9Accepted3/34ms316 KiB
10Accepted3/33ms316 KiB
11Time limit exceeded0/2600ms936 KiB
12Time limit exceeded0/2598ms952 KiB
13Time limit exceeded0/2597ms952 KiB
14Time limit exceeded0/2582ms940 KiB
15Time limit exceeded0/2580ms1016 KiB
16Time limit exceeded0/2583ms1076 KiB
17Time limit exceeded0/2583ms820 KiB
18Time limit exceeded0/2586ms820 KiB
19Time limit exceeded0/2583ms1120 KiB
20Time limit exceeded0/3586ms820 KiB
21Time limit exceeded0/3586ms820 KiB
22Time limit exceeded0/3589ms820 KiB
23Time limit exceeded0/3586ms820 KiB