83562024-01-14 23:33:09zoliBináris fa magassága (50 pont)cpp17Time limit exceeded 20/50600ms4384 KiB
#include <iostream>

using namespace std;
int a[65536]; ///2^16;
int N,M;
int cs[50001],h[50001]; ///csucsok, hosszak
int mhat;
void frissit(int cs, int valt)
{
    a[cs]+=valt;
    if(2*cs<mhat)
    {   frissit(2*cs,valt); frissit(2*cs+1,valt); }
}
int maxmag()
{
    int k=mhat/2;
    int maxi=a[k];
    for(int i=k+1;i<mhat;i++) if(a[i]>maxi)maxi=a[i];
    return maxi;
}
void kiir()
{
    for(int i=1;i<mhat;i++) cout<<a[i]<<" ";
    cout<<endl;
}
void be()
{
    ///inicializal a
    cin>>N>>M;
    mhat=(1<<N);
    a[1]=0;
    for(int i=2;i<mhat;i++)
        a[i]=a[i/2]+1;
    //kiir();
    for(int i=1;i<=M;i++)
    {
        cin>>cs[i]>>h[i];
    }
    for(int i=1;i<=M;i++)
    {
        int valtozas=h[i]-(a[cs[i]]-a[cs[i]/2]);
        frissit(cs[i],valtozas);
        cout<<maxmag()<<"\n";
     //   kiir();
    }
}

int main()
{
    be();

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base20/50
1Accepted0/03ms1888 KiB
2Time limit exceeded0/0600ms1964 KiB
3Accepted2/23ms2320 KiB
4Accepted2/23ms2540 KiB
5Accepted2/23ms2596 KiB
6Accepted2/23ms2724 KiB
7Accepted3/33ms2936 KiB
8Accepted3/33ms3016 KiB
9Accepted3/33ms3148 KiB
10Accepted3/33ms3360 KiB
11Time limit exceeded0/2600ms3348 KiB
12Time limit exceeded0/2546ms3624 KiB
13Time limit exceeded0/2541ms3788 KiB
14Time limit exceeded0/2578ms3912 KiB
15Time limit exceeded0/2600ms4056 KiB
16Time limit exceeded0/2600ms4236 KiB
17Time limit exceeded0/2565ms4304 KiB
18Time limit exceeded0/2563ms4284 KiB
19Time limit exceeded0/2561ms4328 KiB
20Time limit exceeded0/3549ms4280 KiB
21Time limit exceeded0/3559ms4376 KiB
22Time limit exceeded0/3600ms4376 KiB
23Time limit exceeded0/3583ms4384 KiB