192592025-12-03 09:55:27szabelrBináris fa magassága (50 pont)cpp17Wrong answer 0/50118ms1116 KiB
#include <iostream>
#include <cmath>

using namespace std;
int check(int x,int dist[],int best[])
{
    while(x>0)
    {
        best[x]=max(dist[2*x]+best[x*2],dist[2*x+1]+best[x*2+1]);

        x=x/2;
    }
    return best[1];
}
int main()
{
    int dist[65537]{1};
    int best[65537];
    int n,m;
    cin>>n>>m;
    int i=1;
    int x=n-1;
    int a=1;
    while(i<pow(2,n))
    {
        if(i==pow(2,a))
        {
            x--;
            a++;
        }

        best[i]=x;
        i++;
    }
    for(int i=0; i<pow(2,n); i++)
    {
        dist[i]=1;
    }
    int b,c;
    for(int i=0; i<m; i++)
    {
        cin>>b>>c;
        dist[b]=c;
        cout<<check(b/2,dist,best);
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Wrong answer0/01ms564 KiB
2Wrong answer0/0104ms824 KiB
3Wrong answer0/23ms756 KiB
4Wrong answer0/23ms748 KiB
5Wrong answer0/23ms564 KiB
6Wrong answer0/23ms564 KiB
7Wrong answer0/33ms564 KiB
8Wrong answer0/33ms564 KiB
9Wrong answer0/33ms564 KiB
10Wrong answer0/33ms564 KiB
11Wrong answer0/2118ms980 KiB
12Wrong answer0/2118ms928 KiB
13Wrong answer0/2112ms980 KiB
14Wrong answer0/2112ms820 KiB
15Wrong answer0/2115ms1100 KiB
16Wrong answer0/2114ms1116 KiB
17Wrong answer0/2114ms940 KiB
18Wrong answer0/2104ms1072 KiB
19Wrong answer0/2112ms936 KiB
20Wrong answer0/3111ms952 KiB
21Wrong answer0/3114ms820 KiB
22Wrong answer0/3103ms1012 KiB
23Wrong answer0/3104ms824 KiB