119922024-11-24 12:07:57banhelyiBináris fa magassága (50 pont)cpp17Runtime error 0/502ms1004 KiB
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

long int nagy(long int m,long int t[])
{
    long int legnagyobb = 0;
    for(long int i = 0; i< m; i++){
        if(t[i] > legnagyobb){
            legnagyobb = t[i];
        }
        //cout << t[i] << " " ;
    }
    //cout << endl;
    return legnagyobb;
}
int main()
{
    int n = 0;
    int m = 0;
    cin >> n;
    cin >> m;
    int a;
    int b;
    long int legnagyobb = 0;

    int *fa= new int[(long int)pow(2,n)-1];

    for(long int i=0; i < ((long int)2 << n)-1; i++){
        fa[i] = 1;
    }

    long int *level=new long int[((long int)2 << (n-1))];


    for(long int i=0; i < ((long int)2 << (n-1)); i++){
        level[i] = n-1;
    }

    for(int i=0; i < m; i++){
        cin >> a;
        cin >> b;

        //cout << b << " " << fa[a-1] << " ";
        int valt = b - fa[a-1];

        fa[a-1] = b;
        int elso=a;
        int db=1;
        while (elso*2<(long int)pow(2,n)-1){
            elso*=2;
            db*=2;
        }
        //cout<<elso<<" " <<db << " " << valt << " " <<  elso-(int)pow(2,(n-1)) <<endl;
        for(long int j=0; j < db; j++){
            level[elso-((long int)2 << (n-1))+j] += valt;
        }
        cout << nagy(((long int)2 << (n-1)),level) << "\n";
    }


    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Runtime error0/01ms320 KiB
2Runtime error0/01ms568 KiB
3Runtime error0/21ms320 KiB
4Runtime error0/21ms560 KiB
5Runtime error0/21ms508 KiB
6Runtime error0/21ms320 KiB
7Runtime error0/31ms320 KiB
8Runtime error0/31ms320 KiB
9Runtime error0/31ms320 KiB
10Runtime error0/31ms320 KiB
11Runtime error0/21ms568 KiB
12Runtime error0/21ms568 KiB
13Runtime error0/22ms568 KiB
14Runtime error0/21ms680 KiB
15Runtime error0/21ms568 KiB
16Runtime error0/21ms568 KiB
17Runtime error0/21ms1004 KiB
18Runtime error0/21ms672 KiB
19Runtime error0/21ms568 KiB
20Runtime error0/31ms584 KiB
21Runtime error0/31ms568 KiB
22Runtime error0/31ms568 KiB
23Runtime error0/31ms568 KiB