Submission #990535

# Submission time Handle Problem Language Result Execution time Memory
990535 2024-05-30T15:38:30 Z ToniB Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1533 ms 111088 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1e6 + 2;
const int LOG = 20;
const int OFF = 1 << (LOG + 1);

int n, q, w[N], L[N], R[N];

struct Node {
	int idx;
	int val;
} tour[OFF];

Node mrg(Node a, Node b) {
	Node ret = {a.idx, max(a.val, b.val)};
	if (a.idx == -1 || (b.idx != -1 && w[a.idx] <= w[b.idx])) ret.idx = b.idx;
	return ret;
}

void con(int x, int l, int r) {
	if (l == r) {
		tour[x] = {l, w[l] + w[R[l]]};
		if (R[l] == n) tour[x].val = 0;
		return ;
	}
	int mid = (l + r) >> 1;
	con(x * 2 + 1, l, mid);
	con(x * 2 + 2, mid + 1, r);
	tour[x] = mrg(tour[x * 2 + 1], tour[x * 2 + 2]);
}
Node f(int x, int l, int r, int ql, int qr) {
	if (ql <= l && r <= qr) return tour[x];
	if (ql > r || l > qr) return {-1, 0};
	int mid = (l + r) >> 1;
	return mrg(f(x * 2 + 1, l, mid, ql, qr), f(x * 2 + 2, mid + 1, r, ql, qr));
}

void rek(int l, int r, int mx) {
	if (l < mx) {
		L[mx] = f(0, 0, n - 1, l, mx - 1).idx;
		rek(l, mx - 1, L[mx]);
	}
	if (mx < r) {
		R[mx] = f(0, 0, n - 1, mx + 1, r).idx;
		rek(mx + 1, r, R[mx]);
	}
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);

	cin >> n >> q;
	for (int i = 0; i <= n; ++i) {
		L[i] = R[i] = n;
	}
	for (int i = 0; i < n; ++i) cin >> w[i];
	con(0, 0, n - 1);
	rek(0, n - 1, tour[0].idx);
	con(0, 0, n - 1);

	while (q--) {
		int l, r, k;
		cin >> l >> r >> k, --l, --r;
		int idx = f(0, 0, n - 1, l, r).idx, ans = 0;
		if (idx < r) {
			int nxt = f(0, 0, n - 1, idx + 1, r).idx;
			ans = max(ans, w[idx] + w[nxt]);
		}
		if (l < idx) ans = max(ans, f(0, 0, n - 1, l, idx - 1).val);
		cout << (ans <= k) << "\n";
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6608 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6608 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 4 ms 6492 KB Output is correct
12 Correct 4 ms 6748 KB Output is correct
13 Correct 4 ms 6748 KB Output is correct
14 Correct 6 ms 6748 KB Output is correct
15 Correct 6 ms 6744 KB Output is correct
16 Correct 7 ms 7012 KB Output is correct
17 Correct 4 ms 6748 KB Output is correct
18 Correct 5 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1533 ms 30432 KB Output is correct
2 Correct 1511 ms 63316 KB Output is correct
3 Correct 1518 ms 63316 KB Output is correct
4 Correct 1509 ms 63316 KB Output is correct
5 Correct 1267 ms 110276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 109 ms 12960 KB Output is correct
2 Correct 105 ms 14916 KB Output is correct
3 Correct 95 ms 19792 KB Output is correct
4 Correct 95 ms 19596 KB Output is correct
5 Correct 91 ms 19768 KB Output is correct
6 Correct 83 ms 19028 KB Output is correct
7 Correct 87 ms 19028 KB Output is correct
8 Correct 93 ms 16720 KB Output is correct
9 Correct 34 ms 8016 KB Output is correct
10 Correct 88 ms 16976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6608 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 4 ms 6492 KB Output is correct
12 Correct 4 ms 6748 KB Output is correct
13 Correct 4 ms 6748 KB Output is correct
14 Correct 6 ms 6748 KB Output is correct
15 Correct 6 ms 6744 KB Output is correct
16 Correct 7 ms 7012 KB Output is correct
17 Correct 4 ms 6748 KB Output is correct
18 Correct 5 ms 6748 KB Output is correct
19 Correct 245 ms 23888 KB Output is correct
20 Correct 297 ms 23884 KB Output is correct
21 Correct 232 ms 23636 KB Output is correct
22 Correct 232 ms 23636 KB Output is correct
23 Correct 233 ms 23816 KB Output is correct
24 Correct 219 ms 33108 KB Output is correct
25 Correct 195 ms 33368 KB Output is correct
26 Correct 206 ms 33088 KB Output is correct
27 Correct 201 ms 33100 KB Output is correct
28 Correct 212 ms 33356 KB Output is correct
29 Correct 197 ms 33292 KB Output is correct
30 Correct 199 ms 33364 KB Output is correct
31 Correct 206 ms 33364 KB Output is correct
32 Correct 201 ms 33360 KB Output is correct
33 Correct 201 ms 33344 KB Output is correct
34 Correct 198 ms 32852 KB Output is correct
35 Correct 182 ms 32976 KB Output is correct
36 Correct 184 ms 32844 KB Output is correct
37 Correct 186 ms 32676 KB Output is correct
38 Correct 189 ms 32848 KB Output is correct
39 Correct 180 ms 28600 KB Output is correct
40 Correct 132 ms 22356 KB Output is correct
41 Correct 225 ms 25936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6608 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 4 ms 6492 KB Output is correct
12 Correct 4 ms 6748 KB Output is correct
13 Correct 4 ms 6748 KB Output is correct
14 Correct 6 ms 6748 KB Output is correct
15 Correct 6 ms 6744 KB Output is correct
16 Correct 7 ms 7012 KB Output is correct
17 Correct 4 ms 6748 KB Output is correct
18 Correct 5 ms 6748 KB Output is correct
19 Correct 1533 ms 30432 KB Output is correct
20 Correct 1511 ms 63316 KB Output is correct
21 Correct 1518 ms 63316 KB Output is correct
22 Correct 1509 ms 63316 KB Output is correct
23 Correct 1267 ms 110276 KB Output is correct
24 Correct 109 ms 12960 KB Output is correct
25 Correct 105 ms 14916 KB Output is correct
26 Correct 95 ms 19792 KB Output is correct
27 Correct 95 ms 19596 KB Output is correct
28 Correct 91 ms 19768 KB Output is correct
29 Correct 83 ms 19028 KB Output is correct
30 Correct 87 ms 19028 KB Output is correct
31 Correct 93 ms 16720 KB Output is correct
32 Correct 34 ms 8016 KB Output is correct
33 Correct 88 ms 16976 KB Output is correct
34 Correct 245 ms 23888 KB Output is correct
35 Correct 297 ms 23884 KB Output is correct
36 Correct 232 ms 23636 KB Output is correct
37 Correct 232 ms 23636 KB Output is correct
38 Correct 233 ms 23816 KB Output is correct
39 Correct 219 ms 33108 KB Output is correct
40 Correct 195 ms 33368 KB Output is correct
41 Correct 206 ms 33088 KB Output is correct
42 Correct 201 ms 33100 KB Output is correct
43 Correct 212 ms 33356 KB Output is correct
44 Correct 197 ms 33292 KB Output is correct
45 Correct 199 ms 33364 KB Output is correct
46 Correct 206 ms 33364 KB Output is correct
47 Correct 201 ms 33360 KB Output is correct
48 Correct 201 ms 33344 KB Output is correct
49 Correct 198 ms 32852 KB Output is correct
50 Correct 182 ms 32976 KB Output is correct
51 Correct 184 ms 32844 KB Output is correct
52 Correct 186 ms 32676 KB Output is correct
53 Correct 189 ms 32848 KB Output is correct
54 Correct 180 ms 28600 KB Output is correct
55 Correct 132 ms 22356 KB Output is correct
56 Correct 225 ms 25936 KB Output is correct
57 Correct 1443 ms 63948 KB Output is correct
58 Correct 1465 ms 63956 KB Output is correct
59 Correct 1430 ms 64068 KB Output is correct
60 Correct 1464 ms 63940 KB Output is correct
61 Correct 1261 ms 63800 KB Output is correct
62 Correct 1337 ms 63948 KB Output is correct
63 Correct 966 ms 109140 KB Output is correct
64 Correct 1002 ms 109136 KB Output is correct
65 Correct 1120 ms 110928 KB Output is correct
66 Correct 1106 ms 110932 KB Output is correct
67 Correct 1066 ms 111000 KB Output is correct
68 Correct 1092 ms 111004 KB Output is correct
69 Correct 1093 ms 110884 KB Output is correct
70 Correct 1169 ms 111024 KB Output is correct
71 Correct 1107 ms 111088 KB Output is correct
72 Correct 1123 ms 110932 KB Output is correct
73 Correct 964 ms 107476 KB Output is correct
74 Correct 964 ms 108492 KB Output is correct
75 Correct 969 ms 107596 KB Output is correct
76 Correct 1024 ms 107428 KB Output is correct
77 Correct 982 ms 107464 KB Output is correct
78 Correct 1092 ms 89164 KB Output is correct
79 Correct 704 ms 64056 KB Output is correct
80 Correct 1117 ms 78632 KB Output is correct