97422024-03-05 18:00:43matyiBináris fa magassága (50 pont)cpp17Time limit exceeded 20/50600ms4236 KiB
#include <iostream>
#include <fstream>

using namespace std;

int gyorshatvany(int n)
{
    if (n==0)
        return 1;
    else
    {
        int hatvany=gyorshatvany(n/2); // 2^n/2
        if (n%2==0)
        {
            return hatvany * hatvany;
        }
        else
            return hatvany * hatvany * 2;
    }
}

int main()
{

    int n,m;
    //ifstream fin("be.in");
    cin>>n>>m;
    int darabcsucs=gyorshatvany(n);
    int suly[darabcsucs]={0},hossz[darabcsucs/2]={0}, szint[darabcsucs]={0};
    int x,y;
    szint[1]=1;
    for (int i=2;i<darabcsucs;i++)
    {
        suly[i]=1;
        szint[i]=szint[i/2]+1;
    }
    for (int i=0;i<darabcsucs/2;i++)
    {
        hossz[i]=n-1;
    }
    for (int i=1;i<=m;i++)
    {
        cin>>x>>y;
        int kulonbseg=y-suly[x];
        suly[x]=y;
        int hatvany=gyorshatvany(n-szint[x]);
        int kezd=hatvany*x-(darabcsucs/2);
        int veg=kezd+hatvany-1;
        for (int i=kezd;i<=veg;i++)
        {
            hossz[i]+=kulonbseg;
        }
        int maxi=-1;
        for (int i=0;i<darabcsucs/2;i++)
        {
            if (hossz[i]>maxi)
                maxi=hossz[i];
        }
        cout<<maxi<< endl;
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base20/50
1Accepted0/03ms2020 KiB
2Time limit exceeded0/0600ms2032 KiB
3Accepted2/24ms2320 KiB
4Accepted2/24ms2496 KiB
5Accepted2/24ms2748 KiB
6Accepted2/24ms2992 KiB
7Accepted3/34ms3204 KiB
8Accepted3/34ms3288 KiB
9Accepted3/34ms3256 KiB
10Accepted3/34ms3504 KiB
11Time limit exceeded0/2600ms3320 KiB
12Time limit exceeded0/2565ms3512 KiB
13Time limit exceeded0/2577ms3688 KiB
14Time limit exceeded0/2558ms3828 KiB
15Time limit exceeded0/2558ms3832 KiB
16Time limit exceeded0/2554ms3904 KiB
17Time limit exceeded0/2550ms3904 KiB
18Time limit exceeded0/2569ms4216 KiB
19Time limit exceeded0/2569ms4088 KiB
20Time limit exceeded0/3561ms4172 KiB
21Time limit exceeded0/3546ms4164 KiB
22Time limit exceeded0/3569ms4164 KiB
23Time limit exceeded0/3554ms4236 KiB