123102024-12-11 19:48:19ercseferencBináris fa magassága (50 pont)cpp17Time limit exceeded 20/50600ms984 KiB
#include <iostream>
#include <cmath>
using namespace std;
int szint(int n){
    int s=0;
    while(n!=0){
        n=n/2; s++;}
    return s;}
int polc(int n, int p){
    for(int i=0; i<p; i++){n=2*n+1;} return n;}
using namespace std;
int main()
{
    int n,m,cs,v,c,k,r;
    cin>>n; cin>>m;
    c=pow(2,n-1)-1;
    int p=pow(2,n)-1;
    int a[p+1]; for(int i=2; i<=p; i++){a[i]=1;}
    int q=pow(2,n-1); a[0]=0; a[1]=0;
    int b[q+1]; for(int i=1; i<=q; i++){b[i]=n-1;}
    b[0]=0;
    for(int i=0; i<m; i++){
        cin>>cs; cin>>v;
        k=v-a[cs];
        for(int j=cs*pow(2,n-szint(cs))-c; j<=polc(cs,n-szint(cs))-c; j++){
            b[j]=b[j]+k;}
        r=0;
        for(int j=1; j<=q; j++){if(b[j]>r) r=b[j];}
        cout<<r<<endl;
        a[cs]=v;}
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base20/50
1Accepted0/01ms320 KiB
2Time limit exceeded0/0574ms792 KiB
3Accepted2/23ms508 KiB
4Accepted2/23ms320 KiB
5Accepted2/22ms320 KiB
6Accepted2/23ms320 KiB
7Accepted3/33ms320 KiB
8Accepted3/33ms556 KiB
9Accepted3/33ms320 KiB
10Accepted3/33ms320 KiB
11Time limit exceeded0/2600ms796 KiB
12Time limit exceeded0/2600ms792 KiB
13Time limit exceeded0/2600ms824 KiB
14Time limit exceeded0/2592ms984 KiB
15Time limit exceeded0/2586ms828 KiB
16Time limit exceeded0/2587ms780 KiB
17Time limit exceeded0/2587ms820 KiB
18Time limit exceeded0/2583ms568 KiB
19Time limit exceeded0/2591ms568 KiB
20Time limit exceeded0/3591ms788 KiB
21Time limit exceeded0/3593ms804 KiB
22Time limit exceeded0/3583ms828 KiB
23Time limit exceeded0/3580ms788 KiB