120012024-11-24 15:47:52banhelyiBináris fa magassága (50 pont)cpp17Time limit exceeded 20/50600ms1132 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(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/0573ms824 KiB
3Accepted2/23ms500 KiB
4Accepted2/23ms320 KiB
5Accepted2/23ms320 KiB
6Accepted2/23ms320 KiB
7Accepted3/33ms320 KiB
8Accepted3/33ms320 KiB
9Accepted3/33ms320 KiB
10Accepted3/33ms320 KiB
11Time limit exceeded0/2598ms1132 KiB
12Time limit exceeded0/2600ms1084 KiB
13Time limit exceeded0/2598ms944 KiB
14Time limit exceeded0/2577ms824 KiB
15Time limit exceeded0/2573ms824 KiB
16Time limit exceeded0/2575ms940 KiB
17Time limit exceeded0/2600ms952 KiB
18Time limit exceeded0/2583ms952 KiB
19Time limit exceeded0/2586ms940 KiB
20Time limit exceeded0/3587ms824 KiB
21Time limit exceeded0/3600ms948 KiB
22Time limit exceeded0/3591ms824 KiB
23Time limit exceeded0/3586ms824 KiB