90492024-02-13 08:38:33PedriBináris fa magassága (50 pont)cpp17Accepted 50/50128ms5336 KiB
#include <iostream>
#include <fstream>
#include <cmath>

using namespace std;
int n, m;


int main()
{
    ifstream f("be.in");
    cin>>n>>m;
    int ossz=pow(2, n)-1;
    int a[ossz]={1};

    int l[ossz]={0};
    for(int j=1;j<=n;j++){
            for(int i=pow(2, j-1);i<pow(2, j);i++)l[i]=n-j+1;
        }
    for(int i=1;i<=ossz;i++)a[i]=1;
    a[1]=0;
    /*for(int i=1;i<=ossz;i++)cout<<l[i]<<" ";
    cout<<endl;*/
    for(int i=1;i<=m;i++){
        int x, y;
        cin>>x;
        cin>>y;
        int s=0;
        if(y>a[x]){
            a[x]=y;
            while(x!=1 && l[x/2]<l[x]+a[x]){
                    l[x/2]=l[x]+a[x];
                    x=x/2;
            }
        }else {
            a[x]=y;
            while(x!=1){
                if(x%2==0)l[x/2]=max(l[x]+a[x], l[x+1]+a[x+1]);
                else l[x/2]=max(l[x]+a[x], l[x-1]+a[x-1]);
                x=x/2;
            }

        }
        cout<<l[1]-1<<endl;
    }







    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1820 KiB
2Accepted0/083ms3028 KiB
3Accepted2/24ms2236 KiB
4Accepted2/24ms2492 KiB
5Accepted2/24ms2576 KiB
6Accepted2/24ms2528 KiB
7Accepted3/34ms2792 KiB
8Accepted3/34ms2980 KiB
9Accepted3/34ms3096 KiB
10Accepted3/34ms3304 KiB
11Accepted2/286ms4540 KiB
12Accepted2/287ms4624 KiB
13Accepted2/2108ms4624 KiB
14Accepted2/2116ms4628 KiB
15Accepted2/286ms4872 KiB
16Accepted2/282ms5108 KiB
17Accepted2/2120ms5084 KiB
18Accepted2/283ms5332 KiB
19Accepted2/282ms5336 KiB
20Accepted3/382ms5176 KiB
21Accepted3/3128ms5180 KiB
22Accepted3/387ms5300 KiB
23Accepted3/3116ms5308 KiB