89202024-02-05 08:29:39AncsaBináris fa magassága (50 pont)cpp17Time limit exceeded 2/50600ms4220 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 <int> fa(szam);
    vector <int> levelek(lszam+1);
    for(int i=0;i<=lszam;i++)
         levelek.at(i)=n-1;
    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);
        //cout<<"fa eddig"<<fa.at(hol)<<" valtoizas "<<valt<<endl;
        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)
            legnagyobb=*max_element(levelek.begin(),levelek.end());
        else
        {
            int ujnagy = *max_element(levelek.begin()+hol*pow(2,tav)-(lszam-1),levelek.begin()+(hol+1)*pow(2,tav)-lszam);
            if (ujnagy>legnagyobb)
               legnagyobb=ujnagy;
        }

        cout<<legnagyobb<<endl;
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base2/50
1Accepted0/03ms1808 KiB
2Time limit exceeded0/0600ms1732 KiB
3Accepted2/24ms2084 KiB
4Wrong answer0/24ms2336 KiB
5Wrong answer0/24ms2548 KiB
6Wrong answer0/24ms2668 KiB
7Wrong answer0/34ms3036 KiB
8Wrong answer0/34ms3108 KiB
9Wrong answer0/34ms3244 KiB
10Wrong answer0/36ms3460 KiB
11Time limit exceeded0/2523ms4212 KiB
12Time limit exceeded0/2554ms3164 KiB
13Time limit exceeded0/2561ms3388 KiB
14Time limit exceeded0/2535ms3528 KiB
15Time limit exceeded0/2574ms3808 KiB
16Time limit exceeded0/2565ms4076 KiB
17Time limit exceeded0/2558ms4056 KiB
18Time limit exceeded0/2537ms4220 KiB
19Time limit exceeded0/2559ms4184 KiB
20Time limit exceeded0/3550ms4028 KiB
21Time limit exceeded0/3578ms4168 KiB
22Time limit exceeded0/3561ms4020 KiB
23Time limit exceeded0/3550ms4120 KiB