90542024-02-13 11:08:33akososkaBináris fa magassága (50 pont)cpp17Accepted 50/50131ms6376 KiB
#include <iostream>
#include <cmath>

using namespace std;
int n,m;

int main()
{
    cin>>n;
    cin>>m;
    int cs,h,t=pow(2,n),par;
    int a[2*t],b[2*t];
    for(int i=2;i<2*t;i++){
        a[i]=1;
    }
    a[1]=0;
    int s=1;
    for(int j=0;j<n;j++){
        for(int i=1;i<=pow(2,j);i++){
            b[s]=n-j-1;
            s++;
        }
    }
    for(int i=1;i<=m;i++){
        cin>>cs;
        cin>>h;
        a[cs]=h;
        if(h>a[cs]){
            while(cs!=1 && b[cs]+a[cs]>b[cs/2]){
                b[cs/2]=b[cs]+a[cs];
                cs=cs/2;
            }
        }
        else{
            while(cs!=1){
                if(cs%2==0)par=cs+1;
                else par=cs-1;
                if(b[cs]+a[cs]>b[par]+a[par])b[cs/2]=b[cs]+a[cs];
                else b[cs/2]=b[par]+a[par];
                cs=cs/2;
            }
        }
        cout<<b[1]<<endl;
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1872 KiB
2Accepted0/082ms4112 KiB
3Accepted2/24ms2440 KiB
4Accepted2/24ms2424 KiB
5Accepted2/24ms2592 KiB
6Accepted2/24ms2704 KiB
7Accepted3/34ms2696 KiB
8Accepted3/34ms2832 KiB
9Accepted3/34ms2824 KiB
10Accepted3/34ms2920 KiB
11Accepted2/2119ms5292 KiB
12Accepted2/285ms5284 KiB
13Accepted2/2131ms5416 KiB
14Accepted2/2108ms5452 KiB
15Accepted2/287ms5540 KiB
16Accepted2/289ms5612 KiB
17Accepted2/2125ms5608 KiB
18Accepted2/282ms5612 KiB
19Accepted2/282ms5736 KiB
20Accepted3/3104ms5864 KiB
21Accepted3/398ms6040 KiB
22Accepted3/3127ms6244 KiB
23Accepted3/382ms6376 KiB