Submission #1096200

# Submission time Handle Problem Language Result Execution time Memory
1096200 2024-10-04T05:30:40 Z stdfloat Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
2692 ms 262396 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define sz(v)  (int)(v).size()
#define all(v) (v).begin(), v.end()

int mx;

vector<int> a, st, vis;

vector<vector<int>> v;

void bld(int nd, int l, int r) {
	if (l == r) {
		vis[nd] = 0; st[nd] = a[l]; v[nd] = {a[l]};
		return;
	}

	int ch = (nd << 1) + 1, md = l + r >> 1;
	bld(ch, l, md); bld(ch + 1, md + 1, r);

	st[nd] = max(st[ch], st[ch + 1]);

	v[nd].assign(sz(v[ch]) + sz(v[ch + 1]), 0);
	merge(all(v[ch]), all(v[ch + 1]), v[nd].begin());
	
	int mx = 0;
	for (int i = l; i <= r; i++) {
		if (mx > a[i]) vis[nd] = max(vis[nd], mx + a[i]);
		else mx = a[i];
	}
}

bool fnd(int nd, int l, int r, int x, int y, int k) {
	if (r < x || y < l) return true;

	if (x <= l && r <= y) {
		if (vis[nd] > k || (mx > v[nd][0] && mx + *--lower_bound(all(v[nd]), mx) > k)) return false;

		mx = max(mx, st[nd]);
		return true;
	}

	int ch = (nd << 1) + 1, md = l + r >> 1;
	return (!fnd(ch, l, md, x, y, k) || !fnd(ch + 1, md + 1, r, x, y, k) ? false : true);
}

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

	int n, q;
	cin >> n >> q;

	a.assign(n, 0);
	for (auto &i : a)
		cin >> i;

	v.assign(n << 2, {});
	st = vis = vector<int>(n << 2);
	bld(0, 0, n - 1);

	while (q--) {
		int l, r, k;
		cin >> l >> r >> k; l--; r--;

		mx = 0;
		cout << fnd(0, 0, n - 1, l, r, k) << endl;
	}
}

Compilation message

sortbooks.cpp: In function 'void bld(int, int, int)':
sortbooks.cpp:21:33: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   21 |  int ch = (nd << 1) + 1, md = l + r >> 1;
      |                               ~~^~~
sortbooks.cpp: In function 'bool fnd(int, int, int, int, int, int)':
sortbooks.cpp:46:33: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |  int ch = (nd << 1) + 1, md = l + r >> 1;
      |                               ~~^~~
# 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 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 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 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 5 ms 860 KB Output is correct
12 Correct 6 ms 1628 KB Output is correct
13 Correct 6 ms 1608 KB Output is correct
14 Correct 10 ms 1764 KB Output is correct
15 Correct 9 ms 1628 KB Output is correct
16 Correct 11 ms 1728 KB Output is correct
17 Correct 8 ms 1372 KB Output is correct
18 Correct 8 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1872 ms 262144 KB Output is correct
2 Correct 1939 ms 262144 KB Output is correct
3 Correct 2074 ms 262144 KB Output is correct
4 Correct 2078 ms 262144 KB Output is correct
5 Runtime error 2692 ms 262396 KB Memory limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 177 ms 26800 KB Output is correct
2 Correct 169 ms 26528 KB Output is correct
3 Correct 185 ms 26556 KB Output is correct
4 Correct 178 ms 26612 KB Output is correct
5 Correct 181 ms 26704 KB Output is correct
6 Correct 163 ms 26704 KB Output is correct
7 Correct 152 ms 26448 KB Output is correct
8 Correct 156 ms 26708 KB Output is correct
9 Correct 122 ms 1872 KB Output is correct
10 Correct 165 ms 26700 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 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 5 ms 860 KB Output is correct
12 Correct 6 ms 1628 KB Output is correct
13 Correct 6 ms 1608 KB Output is correct
14 Correct 10 ms 1764 KB Output is correct
15 Correct 9 ms 1628 KB Output is correct
16 Correct 11 ms 1728 KB Output is correct
17 Correct 8 ms 1372 KB Output is correct
18 Correct 8 ms 1628 KB Output is correct
19 Correct 419 ms 55892 KB Output is correct
20 Correct 407 ms 54468 KB Output is correct
21 Correct 394 ms 53924 KB Output is correct
22 Correct 390 ms 53840 KB Output is correct
23 Correct 398 ms 53984 KB Output is correct
24 Correct 364 ms 53844 KB Output is correct
25 Correct 372 ms 53844 KB Output is correct
26 Correct 434 ms 54048 KB Output is correct
27 Correct 401 ms 53988 KB Output is correct
28 Correct 449 ms 54352 KB Output is correct
29 Correct 408 ms 54040 KB Output is correct
30 Correct 419 ms 54096 KB Output is correct
31 Correct 412 ms 55740 KB Output is correct
32 Correct 412 ms 55632 KB Output is correct
33 Correct 424 ms 55632 KB Output is correct
34 Correct 340 ms 55116 KB Output is correct
35 Correct 361 ms 53728 KB Output is correct
36 Correct 345 ms 53588 KB Output is correct
37 Correct 345 ms 53760 KB Output is correct
38 Correct 349 ms 53732 KB Output is correct
39 Correct 414 ms 53160 KB Output is correct
40 Correct 346 ms 35708 KB Output is correct
41 Correct 373 ms 52880 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 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 5 ms 860 KB Output is correct
12 Correct 6 ms 1628 KB Output is correct
13 Correct 6 ms 1608 KB Output is correct
14 Correct 10 ms 1764 KB Output is correct
15 Correct 9 ms 1628 KB Output is correct
16 Correct 11 ms 1728 KB Output is correct
17 Correct 8 ms 1372 KB Output is correct
18 Correct 8 ms 1628 KB Output is correct
19 Correct 1872 ms 262144 KB Output is correct
20 Correct 1939 ms 262144 KB Output is correct
21 Correct 2074 ms 262144 KB Output is correct
22 Correct 2078 ms 262144 KB Output is correct
23 Runtime error 2692 ms 262396 KB Memory limit exceeded
24 Halted 0 ms 0 KB -