120022024-11-24 15:48:30banhelyiBináris fa magassága (50 pont)cpp17Time limit exceeded 20/50600ms1016 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(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++){
            if(level[i] > legnagyobb){
                legnagyobb = level[i];
            }
        }

        cout << legnagyobb << "\n";

    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base20/50
1Accepted0/01ms320 KiB
2Time limit exceeded0/0587ms824 KiB
3Accepted2/23ms500 KiB
4Accepted2/23ms320 KiB
5Accepted2/22ms320 KiB
6Accepted2/23ms320 KiB
7Accepted3/33ms320 KiB
8Accepted3/33ms320 KiB
9Accepted3/33ms320 KiB
10Accepted3/33ms320 KiB
11Time limit exceeded0/2600ms944 KiB
12Time limit exceeded0/2598ms940 KiB
13Time limit exceeded0/2600ms948 KiB
14Time limit exceeded0/2578ms824 KiB
15Time limit exceeded0/2575ms944 KiB
16Time limit exceeded0/2578ms824 KiB
17Time limit exceeded0/2578ms824 KiB
18Time limit exceeded0/2587ms824 KiB
19Time limit exceeded0/2582ms1016 KiB
20Time limit exceeded0/3583ms932 KiB
21Time limit exceeded0/3586ms948 KiB
22Time limit exceeded0/3584ms824 KiB
23Time limit exceeded0/3577ms824 KiB