94702024-02-22 09:26:311478Bináris fa magassága (50 pont)cpp17Accepted 50/50128ms4732 KiB
#include <bits/stdc++.h>  
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
double eps = 1e-12;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
ll MOD = 1e9 + 7;


 
int main()
{
	//ifstream cin("in.txt");
	int n, m;
	cin >> n >> m;

	vector<int> dp(1<<n);
	int x = 0;
	for(int j = n; j >= 1; j--){
		for(int i = (1<<j) - 1; i >= (1<<(j-1)); i--){
			dp[i] = x;
		}
		x++;
	}

	vector<int> e(1<<n, 1);

	while(m--){
		int a, b;
		cin >> a >> b;
		e[a] = b;

		int p = a / 2;
		while(p){
			dp[p] = max(dp[p * 2] + e[p * 2], dp[p * 2 + 1] + e[p * 2 + 1]);
			p /= 2;
		}
		cout << dp[1] << '\n';
	}




}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1812 KiB
2Accepted0/082ms2892 KiB
3Accepted2/24ms2360 KiB
4Accepted2/24ms2380 KiB
5Accepted2/24ms2652 KiB
6Accepted2/24ms2720 KiB
7Accepted3/34ms2788 KiB
8Accepted3/34ms2912 KiB
9Accepted3/34ms3008 KiB
10Accepted3/34ms3008 KiB
11Accepted2/286ms3792 KiB
12Accepted2/286ms3984 KiB
13Accepted2/286ms4052 KiB
14Accepted2/286ms4052 KiB
15Accepted2/285ms4204 KiB
16Accepted2/282ms4232 KiB
17Accepted2/283ms4248 KiB
18Accepted2/282ms4464 KiB
19Accepted2/2128ms4476 KiB
20Accepted3/383ms4480 KiB
21Accepted3/382ms4508 KiB
22Accepted3/382ms4508 KiB
23Accepted3/398ms4732 KiB