89222024-02-05 10:44:42AncsaBináris fa magassága (50 pont)cpp17Time limit exceeded 20/50600ms5184 KiB
#include <iostream>
#include <cmath>
#include <bits/stdc++.h>

using namespace std;

/*
3 5
2 6
4 3
6 7
5 4
2 1


*/

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

    vector <long long int> fa(szam);
    vector <long long int> levelek(lszam+1);
    for(int i=0;i<=lszam;i++)
         levelek.at(i)=n-1;
    long long int legnagyobb=n-1;
    fa.at(1)=0;
    for (int i=2;i<szam;i++)
        fa.at(i)=1;
    int muv;
    cin>>muv;
    vector<int> kimenet(muv);

    int hol, mire;
    for (int i=0;i<muv;i++)
    {
        cin>>hol>>mire;
        int szint =(int)log2(hol)+1;
        int tav=n-szint;
        int 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(valt != 0)
        {
              levelek.at(i)+=valt;
              if (valt>0 && levelek.at(i)>legnagyobb)
                 legnagyobb=levelek.at(i);
        }
        if (valt<0)
            legnagyobb=*max_element(levelek.begin(),levelek.end());
        kimenet.at(i)=legnagyobb;
    }
    for(int i=0;i<muv;i++)
    {
        cout<<kimenet.at(i)<<endl;
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base20/50
1Accepted0/03ms2084 KiB
2Time limit exceeded0/0600ms2464 KiB
3Accepted2/24ms2344 KiB
4Accepted2/24ms2504 KiB
5Accepted2/24ms2712 KiB
6Accepted2/24ms2960 KiB
7Accepted3/34ms3088 KiB
8Accepted3/34ms3180 KiB
9Accepted3/34ms3312 KiB
10Accepted3/34ms3348 KiB
11Time limit exceeded0/2515ms5184 KiB
12Time limit exceeded0/2565ms3484 KiB
13Time limit exceeded0/2574ms3420 KiB
14Time limit exceeded0/2574ms3512 KiB
15Time limit exceeded0/2560ms3460 KiB
16Time limit exceeded0/2560ms3516 KiB
17Time limit exceeded0/2569ms3552 KiB
18Time limit exceeded0/2570ms3764 KiB
19Time limit exceeded0/2558ms3788 KiB
20Time limit exceeded0/3550ms3676 KiB
21Time limit exceeded0/3565ms3628 KiB
22Time limit exceeded0/3546ms3740 KiB
23Time limit exceeded0/3578ms4000 KiB