89622024-02-08 06:46:59AncsaBináris fa magassága (50 pont)cpp17Time limit exceeded 30/50600ms5000 KiB
#include <iostream>
#include <cmath>
#include <bits/stdc++.h>

using namespace std;


int main()
{
    int n;
    cin>>n;
    long long int lszam=1<<(n-1), szam=lszam<<1; //levelek
    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> szintek{1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536};
    map<int, int> minden;
    minden[n-1]=(1<<n-1);
    int hol, mire;
    for (int i=0;i<muv;i++)
    {
        bool rendezni = false;
        cin>>hol>>mire;
        int szint=0;
        while(hol>=szintek[szint])
        {
            szint++;
        }
    
        int tav=n-szint;
        int valt=mire-fa.at(hol);


        fa.at(hol)=mire;
        for(int i=(hol<<tav)-(lszam-1);i<=((hol+1)<<tav)-lszam;i++)
          if(valt != 0)
          {
              minden[levelek.at(i)]--;
              if (minden[levelek.at(i)]==0)
                minden.erase(levelek.at(i));
              levelek.at(i)+=valt;
              minden[levelek.at(i)]++;
          }
          int meret=minden.size();
          map<int, int>::iterator itr;
          itr=minden.end();
          --itr;
          cout<<itr->first<<endl;
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base30/50
1Accepted0/03ms1816 KiB
2Time limit exceeded0/0600ms2184 KiB
3Accepted2/24ms2348 KiB
4Accepted2/24ms2308 KiB
5Accepted2/24ms2372 KiB
6Accepted2/24ms2496 KiB
7Accepted3/36ms2584 KiB
8Accepted3/37ms2716 KiB
9Accepted3/39ms3008 KiB
10Accepted3/39ms3184 KiB
11Accepted2/286ms4656 KiB
12Accepted2/290ms4724 KiB
13Accepted2/289ms4604 KiB
14Accepted2/287ms4844 KiB
15Accepted2/2125ms5000 KiB
16Time limit exceeded0/2564ms3816 KiB
17Time limit exceeded0/2582ms3740 KiB
18Time limit exceeded0/2550ms3640 KiB
19Time limit exceeded0/2574ms3768 KiB
20Time limit exceeded0/3541ms3596 KiB
21Time limit exceeded0/3565ms3652 KiB
22Time limit exceeded0/3561ms3612 KiB
23Time limit exceeded0/3550ms3744 KiB