89182024-02-05 08:06:15AncsaBináris fa magassága (50 pont)cpp17Time limit exceeded 20/50600ms2920 KiB
#include <iostream>
#include <cmath>
#include <bits/stdc++.h>

using namespace std;

int main()
{

    int n;
    cin>>n;
    int lszam=pow(2,n-1), szam=2*lszam;

    vector <int> fa(szam);
    vector <int> levelek(lszam+1);
    for(int i=0;i<=lszam;i++)
         levelek.at(i)=n-1;

    fa.at(1)=0;
    for (int i=2;i<szam;i++)
        fa.at(i)=1;
    int muv;
    cin >>muv;
    int hol, mire;
    for (int i=0;i<muv;i++)
    {
        cin>>hol>>mire;
        int szint =(int)log2(hol)+1;
        int tav=n-szint, valt=mire-fa.at(hol);
        fa.at(hol)=mire;
        for(int i=hol*pow(2,tav)-(lszam-1);i<=(hol+1)*pow(2,tav)-lszam;i++)
            if(mire != 0)
              levelek.at(i)+=valt;
        cout<<*max_element(levelek.begin(),levelek.end())<<endl;
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base20/50
1Accepted0/03ms1684 KiB
2Time limit exceeded0/0600ms1572 KiB
3Accepted2/24ms2208 KiB
4Accepted2/24ms2212 KiB
5Accepted2/24ms2280 KiB
6Accepted2/24ms2344 KiB
7Accepted3/34ms2364 KiB
8Accepted3/34ms2568 KiB
9Accepted3/34ms2856 KiB
10Accepted3/34ms2792 KiB
11Time limit exceeded0/2600ms2460 KiB
12Time limit exceeded0/2580ms2632 KiB
13Time limit exceeded0/2549ms2720 KiB
14Time limit exceeded0/2560ms2652 KiB
15Time limit exceeded0/2552ms2600 KiB
16Time limit exceeded0/2569ms2636 KiB
17Time limit exceeded0/2580ms2696 KiB
18Time limit exceeded0/2573ms2828 KiB
19Time limit exceeded0/2564ms2824 KiB
20Time limit exceeded0/3564ms2856 KiB
21Time limit exceeded0/3541ms2920 KiB
22Time limit exceeded0/3569ms2916 KiB
23Time limit exceeded0/3552ms2904 KiB