89672024-02-09 09:25:18AncsaBináris fa magassága (50 pont)cpp17Time limit exceeded 30/50600ms5044 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();
          while (itr->second == 0)
             --itr;
          cout<<itr->first<<endl;

/*
          map<int, int>::iterator itr;
          itr=minden.end();
          --itr;
          cout<<itr->first<<endl;
  */
    }
    return 0;
}




SubtaskSumTestVerdictTimeMemory
base30/50
1Accepted0/03ms1812 KiB
2Time limit exceeded0/0600ms2240 KiB
3Accepted2/24ms2268 KiB
4Accepted2/24ms2428 KiB
5Accepted2/24ms2516 KiB
6Accepted2/24ms2636 KiB
7Accepted3/36ms2884 KiB
8Accepted3/38ms3104 KiB
9Accepted3/39ms3216 KiB
10Accepted3/39ms3460 KiB
11Accepted2/286ms4740 KiB
12Accepted2/2112ms4848 KiB
13Accepted2/2129ms4936 KiB
14Accepted2/2128ms4940 KiB
15Accepted2/2115ms5044 KiB
16Time limit exceeded0/2560ms3848 KiB
17Time limit exceeded0/2569ms3844 KiB
18Time limit exceeded0/2563ms4032 KiB
19Time limit exceeded0/2570ms3984 KiB
20Time limit exceeded0/3546ms4260 KiB
21Time limit exceeded0/3570ms4120 KiB
22Time limit exceeded0/3555ms4260 KiB
23Time limit exceeded0/3542ms4264 KiB