86672024-01-25 03:01:17SleepyOverlordBináris fa magassága (50 pont)cpp17Időlimit túllépés 26/50600ms4356 KiB
#include <vector>
#include <string> 
#include <set> 
#include <map> 
#include <unordered_set>
#include <unordered_map>
#include <queue> 
#include <bitset> 
#include <stack>
#include <list>

#include <numeric> 
#include <algorithm> 
#include <random>
#include <chrono>

#include <cstdio>
#include <fstream>
#include <iostream> 
#include <sstream> 
#include <iomanip>
#include <climits>

#include <cctype>
#include <cmath> 
#include <ctime>
#include <cassert>

using namespace std;

#define ULL unsigned long long
#define LL long long
#define PII pair <int, int>
#define VB vector <bool>
#define VI vector <int>
#define VLL vector <LL>
#define VD vector <double>
#define VS vector <string>
#define VPII vector <pair <int, int> >
#define VVI vector < VI >
#define VVB vector < VB >
#define SI set < int >
#define USI unordered_set <int>
#define MII map <int, int>
#define UMII unordered_map <int, int>
#define MS multiset
#define US unordered_set
#define UM unordered_map
#define UMS unordered_multiset
#define UMM unordered_multimap

#define FORN(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)

#define SZ size()
#define BG begin() 
#define EN end() 
#define CL clear()
#define X first
#define Y second
#define RS resize
#define PB push_back
#define MP make_pair
#define ALL(x) x.begin(), x.end()
#define INS insert
#define ER erase
#define CNT count

template <class T> ostream& operator <<(ostream & os, const vector<T> &vec)
{
	for (int i = 0; i < vec.size() - 1; ++i) os << vec[i] << ' ';
	return os << vec[vec.size() - 1];
}

template <class T1, class T2> ostream& operator <<(ostream & os, const pair<T1, T2> &p)
{
	return os << p.X << " " << p.Y;
}

template <typename T>
void pr(T var1)
{
	cout << var1 << '\n';
}
template <typename T, typename... Types>
void pr(T var1, Types... var2)
{
	cout << var1;
	pr(var2...);
}

void in(int &n, VI &a) //array of ints
{
	cin >> n;
	a.CL, a.RS(n + 1);
	FOR(i, 1, n) cin >> a[i];
}

void in(int &n, VS &a) //array of strings
{
	cin >> n;
	a.CL, a.RS(n + 1);
	FOR(i, 1, n) cin >> a[i];
}

void in(int &n, VPII &a) //array of pairs
{
	cin >> n;
	a.CL, a.RS(n + 1);
	FOR(i, 1, n) cin >> a[i].X >> a[i].Y;
}

void in(int &n, int &m, VVI &g) //unweighted graph
{
	cin >> n >> m;
	g.CL, g.RS(n + 1);
	FOR(i, 1, n)
	{
		int x, y;
		cin >> x >> y;
		g[x].PB(y);
		g[y].PB(x);
	}
}

void in(int &n, VVI &g) //unweighted tree
{
	cin >> n;
	g.CL, g.RS(n + 1);
	FOR(i, 1, n - 1)
	{
		int x, y;
		cin >> x >> y;
		g[x].PB(y);
		g[y].PB(x);
	}
}

void in(int &n, int &m, vector <VPII> &g) //weighted graph
{
	cin >> n >> m;
	g.CL, g.RS(n + 1);
	FOR(i, 1, n)
	{
		int x, y, z;
		cin >> x >> y >> z;
		g[x].PB({y, z});
		g[y].PB({x, z});
	}
}

void in(int &n, vector <VPII> &g) //weighted tree
{
	cin >> n;
	g.CL, g.RS(n + 1);
	FOR(i, 1, n - 1)
	{
		int x, y, z;
		cin >> x >> y >> z;
		g[x].PB({y, z});
		g[y].PB({x, z});
	}
}

int n, nn, q, h;
VI a, d;

void df(int node, int delta, bool &changed)
{
	if (node > n) return;
	if (d[node] == h) changed = true;
	d[node] += delta;
	if (d[node] > h) h = d[node];
	df(node * 2, delta, changed);
	df(node * 2 + 1, delta, changed);
}

int main()
{
	#ifdef AT_HOME
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);
	#endif

	cin >> nn >> q;
	h = nn - 1;
	n = (1 << nn) - 1;
	a.RS(n + 1);
	d.RS(n + 1);
	a[1] = 0;
	d[1] = 0;
	FOR(i, 2, n) a[i] = 1, d[i] = d[i / 2] + 1;

	FOR(i, 1, q)
	{
		int node, cost;
		cin >> node >> cost;
		int delta = cost - a[node];
		a[node] = cost;
		bool chg = false;
		df(node, delta, chg);
		if (delta < 0 and chg)
		{
			h = 0;
			FOR(j, n / 2 + 1, n) h = max(h, d[j]);
		}
		pr(h);
	}

	return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base26/50
1Elfogadva0/03ms1876 KiB
2Időlimit túllépés0/0600ms1788 KiB
3Elfogadva2/24ms2344 KiB
4Elfogadva2/24ms2544 KiB
5Elfogadva2/24ms2752 KiB
6Elfogadva2/24ms2816 KiB
7Elfogadva3/34ms3016 KiB
8Elfogadva3/34ms3224 KiB
9Elfogadva3/34ms3360 KiB
10Elfogadva3/34ms3472 KiB
11Elfogadva2/2212ms4228 KiB
12Elfogadva2/2326ms4228 KiB
13Elfogadva2/2430ms4332 KiB
14Időlimit túllépés0/2522ms4356 KiB
15Időlimit túllépés0/2569ms3288 KiB
16Időlimit túllépés0/2560ms3420 KiB
17Időlimit túllépés0/2573ms3528 KiB
18Időlimit túllépés0/2574ms3624 KiB
19Időlimit túllépés0/2565ms3740 KiB
20Időlimit túllépés0/3542ms3740 KiB
21Időlimit túllépés0/3574ms3824 KiB
22Időlimit túllépés0/3580ms4008 KiB
23Időlimit túllépés0/3580ms4004 KiB