89212024-02-05 08:34:54AncsaBináris fa magassága (50 pont)cpp17Time limit exceeded 2/50600ms4780 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);
        //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/03ms1820 KiB
2Time limit exceeded0/0600ms2112 KiB
3Accepted2/24ms2280 KiB
4Wrong answer0/24ms2464 KiB
5Wrong answer0/24ms2672 KiB
6Wrong answer0/24ms2884 KiB
7Wrong answer0/34ms3204 KiB
8Wrong answer0/34ms3220 KiB
9Wrong answer0/34ms3332 KiB
10Wrong answer0/36ms3588 KiB
11Time limit exceeded0/2528ms4780 KiB
12Time limit exceeded0/2550ms3352 KiB
13Time limit exceeded0/2561ms3516 KiB
14Time limit exceeded0/2574ms3648 KiB
15Time limit exceeded0/2569ms3824 KiB
16Time limit exceeded0/2546ms3916 KiB
17Time limit exceeded0/2546ms4092 KiB
18Time limit exceeded0/2550ms4104 KiB
19Time limit exceeded0/2565ms4172 KiB
20Time limit exceeded0/3546ms4228 KiB
21Time limit exceeded0/3561ms4288 KiB
22Time limit exceeded0/3578ms4448 KiB
23Time limit exceeded0/3574ms4456 KiB