125172024-12-21 13:14:29feheristvanBináris fa magassága (50 pont)cpp17Wrong answer 0/50601ms26604 KiB
#include <iostream>
#include <set>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
    vector <set<int>> elemek;
    /// i apja i / 2
    vector <int> ertek;
    int n, m;
    cin >> n >> m;
    int elemeksz = pow(2, n - 1);
    int maxim = n - 1;
    ertek.resize(n + 1 , 1);
    vector <int> magassag;
    magassag.resize(n + 1, n - 1);
    elemek.resize(elemeksz + 1);
    int a = 1, b = 0, hatvany = 2, k = elemeksz;
    for(int i = 1; i < elemeksz * 2; i ++){
        if(i < hatvany){
            a = b + 1;
            b = a + k - 1;
        } else{
            k /= 2;
            a = 1;
            b = a + k - 1;
            hatvany *= 2;
        }
        for(int j = a; j <= b; j ++){
            elemek[j].insert(i);
          //  cout << i << " ";
        }
       // cout << endl;
    }
    int x, y, apax, seged;
    vector <int> maxok;
    for(int i = 0; i < m; i ++){
        cin >> x >> y;
        apax = x / 2;
        seged = ertek[apax];
        ertek[apax] = y;
        for(int i = 1; i <= elemeksz; i ++){
            if(elemek[i].find(x) != elemek[i].end() and elemek[i].find(apax) != elemek[i].end()){
                magassag[i] = magassag[i] - seged + y;
            }
        }
        maxim = magassag[1];
        for(int i = 2; i <= elemeksz; i ++){
            if(magassag[i] > maxim){
                maxim = magassag[i];
            }
        }
        maxok.push_back(maxim);
    }
    for(auto i : maxok)
        cout << i << endl;
    /*
    for(int i = 1; i <= elemeksz; i ++){
        for(auto x : elemek[i]){
            cout << x << " ";
        }
        cout << endl;
    } */
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Wrong answer0/01ms320 KiB
2Runtime error0/065ms26424 KiB
3Wrong answer0/23ms572 KiB
4Wrong answer0/23ms320 KiB
5Runtime error0/23ms320 KiB
6Runtime error0/23ms320 KiB
7Runtime error0/31ms320 KiB
8Runtime error0/31ms320 KiB
9Runtime error0/31ms428 KiB
10Runtime error0/31ms320 KiB
11Time limit exceeded0/2601ms26524 KiB
12Time limit exceeded0/2587ms26428 KiB
13Time limit exceeded0/2589ms26424 KiB
14Time limit exceeded0/2584ms26564 KiB
15Time limit exceeded0/2588ms26572 KiB
16Runtime error0/270ms26424 KiB
17Runtime error0/254ms26484 KiB
18Runtime error0/254ms26424 KiB
19Runtime error0/274ms26436 KiB
20Time limit exceeded0/3601ms26424 KiB
21Time limit exceeded0/3589ms26604 KiB
22Time limit exceeded0/3583ms26420 KiB
23Runtime error0/3314ms26424 KiB