84572024-01-16 20:25:55zoliBináris fa magassága (50 pont)cpp17Wrong answer 4/5039ms6248 KiB
#include <iostream>

using namespace std;
int a[65536]; ///2^16;
int os[65536];
int N,M;
int cs[50001],h[50001]; ///csucsok, hosszak
int mhat,min_lev;
void frissit(int cs)
{
    int i=cs/2;
    int regi;
    while(i>=1)
    {
        regi=a[i];
        {
            a[i]=max(a[2*i]+os[2*i],a[2*i+1]+os[2*i+1]);
            if(a[i]==regi) break;
            i=i/2;
        }
    }
}
void kiir()
{
    for(int i=1;i<mhat;i++) cout<<a[i]<<" ";
    cout<<endl;
}
void be()
{
    ///inicializal a
    cin>>N>>M;
    mhat=(1<<N);
    min_lev=mhat/2; /// elso level indexe
    for(int i=min_lev-1;i>=1;i--)
        a[i]=a[2*i]+1; /// az elejen minden el hossza 1, tehat mindegy a magassagot hol merem
    //kiir();
    for(int i=2;i<=N;i++) os[i]=1; /// i osetol az el hossza
    for(int i=1;i<=M;i++)
    {
        cin>>cs[i]>>h[i];
    }
    for(int i=1;i<=M;i++)
    {
        if(h[i]!=os[cs[i]]) ///ha valtozik a hossz
        {
            os[cs[i]]=h[i];
            frissit(cs[i]);
        }
        cout<<a[1]<<"\n";
         // kiir();
    }
}

int main()
{
    be();

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base4/50
1Accepted0/03ms2168 KiB
2Wrong answer0/034ms3676 KiB
3Accepted2/23ms2308 KiB
4Accepted2/23ms2440 KiB
5Wrong answer0/23ms2656 KiB
6Wrong answer0/23ms2868 KiB
7Wrong answer0/33ms3084 KiB
8Wrong answer0/33ms3284 KiB
9Wrong answer0/33ms3508 KiB
10Wrong answer0/33ms3720 KiB
11Wrong answer0/237ms5068 KiB
12Wrong answer0/237ms5068 KiB
13Wrong answer0/237ms5216 KiB
14Wrong answer0/239ms5184 KiB
15Wrong answer0/239ms5184 KiB
16Wrong answer0/234ms5612 KiB
17Wrong answer0/234ms5616 KiB
18Wrong answer0/234ms5840 KiB
19Wrong answer0/234ms5972 KiB
20Wrong answer0/335ms5952 KiB
21Wrong answer0/335ms6044 KiB
22Wrong answer0/334ms6164 KiB
23Wrong answer0/335ms6248 KiB