Submission #948433

# Submission time Handle Problem Language Result Execution time Memory
948433 2024-03-18T05:55:42 Z brendonw Rabbit Carrot (LMIO19_triusis) C++17
100 / 100
275 ms 30080 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
using pll = pair<ll, ll>;
const ll MAX_A = 5e3;

template<typename T>
struct segtree {
	T size;
	vector<T> val;
	T id = 0;

	segtree(T n) {
		size = 1;
		while (size < n) {
			size *= 2;
		}
		val.assign(size * 2, id);
	}

	void update(T i, T v, T x, T lx, T rx) {
		if (rx - lx == 1) {
			val[x] = v;
			return;
		}
		T mid = (lx + rx) / 2;
		if (i < mid) {
			update(i, v, 2 * x + 1, lx, mid);
		} else {
			update(i, v, 2 * x + 2, mid, rx);
		}
		val[x] = max(val[2 * x + 1], val[2 * x + 2]);
	}

	void update(T i, T v) {
		update(i, v, 0, 0, size);
	}

	T query(T l, T r, T x, T lx, T rx) {
		if (r <= lx || l >= rx) {
			return id;
		}
		if (lx >= l && rx <= r) {
			return val[x];
		}
		T mid = (lx + rx) / 2;
		T calc1 = query(l, r, 2 * x + 1, lx, mid);
		T calc2 = query(l, r, 2 * x + 2, mid, rx);
		return max(calc1, calc2);
	}

	T query(T l, T r) {
		if (l >= r) {
			return -1;
		}
		return query(l, r, 0, 0, size);
	}
};


int solve() {
	ll n, m;
	cin >> n >> m;
	vector<ll> a(n);
	set<ll> heights;
	for (ll i = 0; i < n; ++i) {
		cin >> a[i];
		a[i] -= (i + 1) * m;
		heights.insert(a[i]);
	}
	heights.insert(0);
	ll cnt = 0;
	map<ll, ll> idx;
	for (ll i: heights) {
		if (!idx.count(i)) { idx[i] = ++cnt; }
	}
	segtree<ll> dp(idx.size() + 1);
	for (ll i = 0; i < n; ++i) {
		a[i] = idx[a[i]];
		ll max_prev = dp.query(a[i], idx[0] + 1);
		dp.update(a[i], max_prev + 1);
	}

	cout << n - dp.query(0, idx.size() + 1);

	return 0;
}

#ifndef MY_UNIT_TEST

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
}

#endif
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 452 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 452 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 456 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 3 ms 860 KB Output is correct
21 Correct 3 ms 1116 KB Output is correct
22 Correct 3 ms 860 KB Output is correct
23 Correct 4 ms 1112 KB Output is correct
24 Correct 3 ms 1112 KB Output is correct
25 Correct 4 ms 1116 KB Output is correct
26 Correct 3 ms 1116 KB Output is correct
27 Correct 1 ms 520 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 3 ms 1116 KB Output is correct
30 Correct 3 ms 1132 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 3 ms 1116 KB Output is correct
33 Correct 3 ms 1368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 3 ms 1116 KB Output is correct
6 Correct 3 ms 860 KB Output is correct
7 Correct 4 ms 1112 KB Output is correct
8 Correct 3 ms 1112 KB Output is correct
9 Correct 4 ms 1116 KB Output is correct
10 Correct 3 ms 1116 KB Output is correct
11 Correct 1 ms 520 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 3 ms 1116 KB Output is correct
14 Correct 3 ms 1132 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 3 ms 1368 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 452 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 3 ms 1116 KB Output is correct
35 Correct 3 ms 1228 KB Output is correct
36 Correct 5 ms 1116 KB Output is correct
37 Correct 3 ms 1200 KB Output is correct
38 Correct 1 ms 536 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 2 ms 852 KB Output is correct
41 Correct 1 ms 1012 KB Output is correct
42 Correct 3 ms 1112 KB Output is correct
43 Correct 3 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1116 KB Output is correct
2 Correct 3 ms 1228 KB Output is correct
3 Correct 5 ms 1116 KB Output is correct
4 Correct 3 ms 1200 KB Output is correct
5 Correct 1 ms 536 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 852 KB Output is correct
8 Correct 1 ms 1012 KB Output is correct
9 Correct 3 ms 1112 KB Output is correct
10 Correct 3 ms 1116 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 456 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 3 ms 860 KB Output is correct
15 Correct 3 ms 1116 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 4 ms 1112 KB Output is correct
18 Correct 3 ms 1112 KB Output is correct
19 Correct 4 ms 1116 KB Output is correct
20 Correct 3 ms 1116 KB Output is correct
21 Correct 1 ms 520 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 3 ms 1116 KB Output is correct
24 Correct 3 ms 1132 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 3 ms 1116 KB Output is correct
27 Correct 3 ms 1368 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 0 ms 452 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 181 ms 28376 KB Output is correct
45 Correct 275 ms 30080 KB Output is correct
46 Correct 245 ms 29756 KB Output is correct
47 Correct 239 ms 29780 KB Output is correct
48 Correct 170 ms 28244 KB Output is correct
49 Correct 180 ms 29004 KB Output is correct
50 Correct 22 ms 3932 KB Output is correct
51 Correct 19 ms 3932 KB Output is correct
52 Correct 130 ms 15900 KB Output is correct
53 Correct 15 ms 3164 KB Output is correct
54 Correct 186 ms 28756 KB Output is correct
55 Correct 182 ms 28752 KB Output is correct