90532024-02-13 11:07:23akososkaBináris fa magassága (50 pont)cpp17Wrong answer 0/503ms3452 KiB
#include <iostream>
#include <fstream>
#include <cmath>

using namespace std;
int n,m;

int main()
{
    ifstream f("be.in");
    f>>n;
    f>>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++){
        f>>cs;
        f>>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
base0/50
1Wrong answer0/03ms1808 KiB
2Wrong answer0/03ms2060 KiB
3Wrong answer0/23ms2332 KiB
4Wrong answer0/23ms2420 KiB
5Wrong answer0/23ms2676 KiB
6Wrong answer0/22ms2660 KiB
7Wrong answer0/32ms2720 KiB
8Wrong answer0/33ms2848 KiB
9Wrong answer0/32ms2824 KiB
10Wrong answer0/32ms2828 KiB
11Wrong answer0/22ms2956 KiB
12Wrong answer0/22ms2828 KiB
13Wrong answer0/22ms2828 KiB
14Wrong answer0/23ms2956 KiB
15Wrong answer0/22ms2896 KiB
16Wrong answer0/23ms3120 KiB
17Wrong answer0/22ms3104 KiB
18Wrong answer0/23ms3336 KiB
19Wrong answer0/22ms3448 KiB
20Wrong answer0/32ms3336 KiB
21Wrong answer0/32ms3436 KiB
22Wrong answer0/32ms3348 KiB
23Wrong answer0/32ms3452 KiB