Submission #570511

#TimeUsernameProblemLanguageResultExecution timeMemory
570511cheissmartThe short shank; Redemption (BOI21_prison)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

string _reset = "\u001b[0m", _yellow = "\u001b[33m", _bold = "\u001b[1m";
void DBG() { cerr << "]" << _reset << endl; }
template<class H, class...T> void DBG(H h, T ...t) {
	cerr << to_string(h);
	if(sizeof ...(t)) cerr << ", ";
	DBG(t...);
}
#ifdef CHEISSMART
#define debug(...) cerr << _yellow << _bold << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define debug(...)
#endif

const int INF = 1e9 + 7, N = 2e6 + 7;

int a[N], p[N], down[N];
vi G[N];

void dfs(int u) {
	down[u] = 1;
	for(int v:G[u]) {
		dfs(v);
		down[u] = max(down[u], down[v] + 1);
	}
}

vi hebe[N];

signed main()
{
	IO_OP;

	int n, d, t;
	cin >> n >> d >> t;
	int ans = n;

	V<pi> stk, aux;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		if(a[i] <= t) {
			int r = i + t - a[i];
			while(SZ(stk) && stk.back().S <= r) stk.pop_back();
			stk.EB(i, r);
		} else {
			while(SZ(stk) && stk.back().S < i) stk.pop_back();
			if(SZ(stk)) {
				// [stk.back().F, i)
				aux.EB(i, (i + 1));
				aux.EB(stk.back().F, -(i + 1));
			} else {
				ans--;
			}
		}
	}
	
	vi nodes;

	int lst = 0, tp = 1;
	for(auto[pos, op]:aux) {
		int u = abs(op);
		if(op > 0) {
			assert(pos != lst_pos);
			if(tp == 1) p[u] = lst;
			else p[u] = p[lst];
			nodes.PB(u);
		}
		lst = u, tp = op > 0;
	}

	for(int u:nodes) if(p[u]) {
		G[p[u]].PB(u);
	}
	for(int u:nodes) if(!p[u]) {
		dfs(u);
		hebe[down[u]].PB(u);
	}

	function<void(int)> go = [&] (int u) {
		int nxt = -1;
		for(int v:G[u]) if(down[v] + 1 == down[u]) nxt = v;
		for(int v:G[u]) if(v != nxt) hebe[down[v]].PB(v);
		if(nxt != -1)
			go(nxt);
	};

	for(int i = n; i >= 1 && d; i--) {
		while(d && SZ(hebe[i])) {
			int u = hebe[i].back();
			hebe[i].pop_back();
			go(u);
			assert(down[u] == i);
			ans -= i;
			d--;
		}
	}
	cout << ans << '\n';

}

Compilation message (stderr)

prison.cpp: In function 'int main()':
prison.cpp:76:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   76 |  for(auto[pos, op]:aux) {
      |          ^
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from prison.cpp:1:
prison.cpp:79:18: error: 'lst_pos' was not declared in this scope
   79 |    assert(pos != lst_pos);
      |                  ^~~~~~~