120032024-11-24 15:57:13banhelyiBináris fa magassága (50 pont)cpp17Wrong answer 0/50600ms788 KiB
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
    int n = 0;
    int m = 0;
    cin >> n;
    cin >> m;
    long int a;
    long int b;

    unsigned long int fameret=((long int)1 << n) - 1;
    int *fa= new int[fameret];
    for(unsigned long int i=0; i < fameret; i++){
        fa[i] = 1;
    }

    unsigned long int levelmeret=(long int)1 << (n-1);
    //unsigned long int *level=new unsigned long int[levelmeret];
    //for(unsigned long int i=0; i < levelmeret; i++){
    //    level[i] = n-1;
    //}

    for(unsigned long int k=0; k < m; k++){
        cin >> a;
        cin >> b;

        int valt = b - fa[a-1];
        fa[a-1] = b;
        
	unsigned long int elso=a;
        unsigned long int db=1;
        while (elso*2<fameret){
            elso*=2;
            db*=2;
        }
        
	//for(unsigned long int j=0; j < db; j++){
        //    level[elso-levelmeret+j] += valt;
        //}
        
	unsigned long int legnagyobb = 0;

        for(unsigned long int i = 0; i < levelmeret; i++){
	    unsigned long int level = levelmeret+i;
	    unsigned long int osszeg = 0;
	    while (level>0) {
		osszeg+=fa[level];
		level >>=1;
	    }
		
            if(osszeg > legnagyobb){
                legnagyobb = osszeg;
            }
        }

        cout << legnagyobb << "\n";

    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Wrong answer0/01ms508 KiB
2Time limit exceeded0/0577ms568 KiB
3Wrong answer0/23ms320 KiB
4Wrong answer0/23ms320 KiB
5Wrong answer0/22ms320 KiB
6Wrong answer0/23ms320 KiB
7Wrong answer0/33ms320 KiB
8Wrong answer0/33ms320 KiB
9Wrong answer0/34ms320 KiB
10Wrong answer0/34ms320 KiB
11Time limit exceeded0/2598ms688 KiB
12Time limit exceeded0/2598ms680 KiB
13Time limit exceeded0/2600ms680 KiB
14Time limit exceeded0/2583ms568 KiB
15Time limit exceeded0/2587ms748 KiB
16Time limit exceeded0/2587ms568 KiB
17Time limit exceeded0/2587ms568 KiB
18Time limit exceeded0/2591ms568 KiB
19Time limit exceeded0/2575ms568 KiB
20Time limit exceeded0/3575ms568 KiB
21Time limit exceeded0/3578ms788 KiB
22Time limit exceeded0/3588ms568 KiB
23Time limit exceeded0/3579ms748 KiB