181252025-10-01 11:21:12szjBináris fa magassága (50 pont)cpp17Time limit exceeded 20/50600ms2868 KiB
#include <bits/stdc++.h>
using namespace std;
int max = 0;
int main()
{
    //ifstream cin("f.txt");
    int i, n, m, a, b, n1,n2, j;
    cin >> n >> m;
    int num = pow(2, n), id = pow(2, n-1), ma = 0;
    int t[num];
    fill(t, t+num, n-1);
    map<int, int> vec;
    map<int, int> volt;
    for(i=id; i<num; i++)vec.insert({i, i-id});
    for(i=0; i<m; i++)
    {
      cin >> a >> b;
      if(volt.count(a))
      {
          n1 =b;
          b -= volt[a];
          volt[a]=n1;
      }
      else
      {
          volt.insert({a, b});
          b--;
      }
      n1 = a;
      n2 = a;
      while(n1<id)
      {
          n1*=2;
          n2 = n2*2+1;
      }
      for(j=vec[n1]; j<=vec[n2]; j++)
      {
          t[j]+=b;
      }
      cout << *max_element(t, t+num)<<endl;
    }
    return 0;
}

SubtaskSumTestVerdictTimeMemory
base20/50
1Accepted0/01ms316 KiB
2Time limit exceeded0/0583ms2356 KiB
3Accepted2/23ms316 KiB
4Accepted2/23ms316 KiB
5Accepted2/23ms316 KiB
6Accepted2/23ms316 KiB
7Accepted3/33ms508 KiB
8Accepted3/33ms512 KiB
9Accepted3/34ms316 KiB
10Accepted3/34ms500 KiB
11Time limit exceeded0/2600ms2760 KiB
12Time limit exceeded0/2600ms2732 KiB
13Time limit exceeded0/2600ms2732 KiB
14Time limit exceeded0/2582ms2868 KiB
15Time limit exceeded0/2588ms2864 KiB
16Time limit exceeded0/2587ms2252 KiB
17Time limit exceeded0/2587ms2356 KiB
18Time limit exceeded0/2591ms2356 KiB
19Time limit exceeded0/2591ms2352 KiB
20Time limit exceeded0/3591ms2656 KiB
21Time limit exceeded0/3592ms2864 KiB
22Time limit exceeded0/3587ms2868 KiB
23Time limit exceeded0/3579ms2612 KiB