119942024-11-24 12:15:19banhelyiBináris fa magassága (50 pont)cpp17Time limit exceeded 20/50600ms1200 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)1 << n)-1];

    //cout<< ((long int)1 << n)-1 <<endl;

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

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


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


    return 0;
}
SubtaskSumTestVerdictTimeMemory
base20/50
1Accepted0/01ms320 KiB
2Time limit exceeded0/0588ms940 KiB
3Accepted2/23ms320 KiB
4Accepted2/23ms320 KiB
5Accepted2/23ms548 KiB
6Accepted2/23ms320 KiB
7Accepted3/33ms372 KiB
8Accepted3/34ms320 KiB
9Accepted3/33ms320 KiB
10Accepted3/33ms320 KiB
11Time limit exceeded0/2598ms936 KiB
12Time limit exceeded0/2600ms1200 KiB
13Time limit exceeded0/2598ms964 KiB
14Time limit exceeded0/2582ms824 KiB
15Time limit exceeded0/2588ms824 KiB
16Time limit exceeded0/2588ms824 KiB
17Time limit exceeded0/2588ms948 KiB
18Time limit exceeded0/2592ms1012 KiB
19Time limit exceeded0/2586ms992 KiB
20Time limit exceeded0/3586ms828 KiB
21Time limit exceeded0/3587ms824 KiB
22Time limit exceeded0/3586ms824 KiB
23Time limit exceeded0/3575ms948 KiB