119902024-11-24 11:59:29banhelyiBináris fa magassága (50 pont)cpp17Time limit exceeded 20/50600ms956 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[(int)pow(2,n)-1];

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

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


    for(long int i=0; i < pow(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<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-(int)pow(2,(n-1))+j] += valt;
        }
        cout << nagy(pow(2,(n-1)),level) << "\n";
    }


    return 0;
}
SubtaskSumTestVerdictTimeMemory
base20/50
1Accepted0/01ms320 KiB
2Time limit exceeded0/0583ms824 KiB
3Accepted2/23ms320 KiB
4Accepted2/23ms508 KiB
5Accepted2/23ms320 KiB
6Accepted2/23ms320 KiB
7Accepted3/33ms320 KiB
8Accepted3/33ms320 KiB
9Accepted3/34ms320 KiB
10Accepted3/34ms320 KiB
11Time limit exceeded0/2598ms940 KiB
12Time limit exceeded0/2598ms956 KiB
13Time limit exceeded0/2598ms944 KiB
14Time limit exceeded0/2593ms824 KiB
15Time limit exceeded0/2587ms824 KiB
16Time limit exceeded0/2600ms940 KiB
17Time limit exceeded0/2600ms944 KiB
18Time limit exceeded0/2591ms944 KiB
19Time limit exceeded0/2582ms944 KiB
20Time limit exceeded0/3600ms944 KiB
21Time limit exceeded0/3598ms936 KiB
22Time limit exceeded0/3592ms824 KiB
23Time limit exceeded0/3583ms824 KiB