Submission #973403

# Submission time Handle Problem Language Result Execution time Memory
973403 2024-05-01T23:09:26 Z colossal_pepe Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1254 ms 106264 KB
#include <bits/stdc++.h>
using namespace std;

const int INF = 1e9;

struct SGT {
	int n;
	vector<int> tree;
	SGT(int _n) {
		n = _n;
		tree.resize(4 * n, 0);
	}
	void update(int node, int l, int r, int idx, int x) {
		if (l == r) tree[node] = x;
		else {
			int mid = (l + r) / 2;
			if (idx <= mid) update(2 * node, l, mid, idx, x);
			else update(2 * node + 1, mid + 1, r, idx, x);
			tree[node] = max(tree[2 * node], tree[2 * node + 1]);
		}
	}
	int query(int node, int l, int r, int L, int R) {
		if (R < l or r < L) return 0;
		else if (L <= l and r <= R) return tree[node];
		else{
			int mid = (l + r) / 2;
			return max(query(2 * node, l, mid, L, R), query(2 * node + 1, mid + 1, r, L, R));
		}
	}
};

int n, m;
vector<int> a, ans;
vector<pair<int, int>> q;
vector<vector<int>> r2q;

void solve() {
	ans.resize(m);
	SGT sgt = SGT(n);
	stack<int> st;
	for (int r = 0; r < n; r++) {
		while (not st.empty() and a[st.top()] <= a[r]) st.pop();
		if (not st.empty()) sgt.update(1, 0, n - 1, st.top(), a[st.top()] + a[r]);
		st.push(r);
		for (int qi : r2q[r]) {
			auto [l, k] = q[qi];
			ans[qi] = (k >= sgt.query(1, 0, n - 1, l, r));
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> m;
	a.resize(n);
	for (int &x : a) {
		cin >> x;
	}
	q.resize(m), r2q.resize(n);
	for (int i = 0; i < m; i++) {
		int l, r, k;
		cin >> l >> r >> k;
		l--, r--;
		q[i] = make_pair(l, k);
		r2q[r].push_back(i);
	}
	solve();
	for (int i = 0; i < m; i++) {
		cout << ans[i] << '\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 3 ms 604 KB Output is correct
14 Correct 3 ms 604 KB Output is correct
15 Correct 3 ms 604 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 3 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1138 ms 73152 KB Output is correct
2 Correct 1099 ms 106264 KB Output is correct
3 Correct 1101 ms 105996 KB Output is correct
4 Correct 1114 ms 106148 KB Output is correct
5 Correct 972 ms 106140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 7804 KB Output is correct
2 Correct 57 ms 8532 KB Output is correct
3 Correct 59 ms 9308 KB Output is correct
4 Correct 54 ms 9308 KB Output is correct
5 Correct 61 ms 9364 KB Output is correct
6 Correct 44 ms 8272 KB Output is correct
7 Correct 44 ms 8284 KB Output is correct
8 Correct 59 ms 9176 KB Output is correct
9 Correct 25 ms 3532 KB Output is correct
10 Correct 48 ms 8900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 3 ms 604 KB Output is correct
14 Correct 3 ms 604 KB Output is correct
15 Correct 3 ms 604 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 3 ms 604 KB Output is correct
19 Correct 158 ms 18772 KB Output is correct
20 Correct 157 ms 21252 KB Output is correct
21 Correct 132 ms 19268 KB Output is correct
22 Correct 137 ms 19152 KB Output is correct
23 Correct 152 ms 19276 KB Output is correct
24 Correct 111 ms 19012 KB Output is correct
25 Correct 120 ms 18880 KB Output is correct
26 Correct 137 ms 20016 KB Output is correct
27 Correct 140 ms 20176 KB Output is correct
28 Correct 122 ms 20264 KB Output is correct
29 Correct 133 ms 21244 KB Output is correct
30 Correct 132 ms 21012 KB Output is correct
31 Correct 137 ms 21184 KB Output is correct
32 Correct 126 ms 21076 KB Output is correct
33 Correct 128 ms 21072 KB Output is correct
34 Correct 115 ms 18776 KB Output is correct
35 Correct 103 ms 18748 KB Output is correct
36 Correct 101 ms 18440 KB Output is correct
37 Correct 104 ms 18512 KB Output is correct
38 Correct 100 ms 18768 KB Output is correct
39 Correct 120 ms 19412 KB Output is correct
40 Correct 101 ms 15304 KB Output is correct
41 Correct 112 ms 19144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 3 ms 604 KB Output is correct
14 Correct 3 ms 604 KB Output is correct
15 Correct 3 ms 604 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 3 ms 604 KB Output is correct
19 Correct 1138 ms 73152 KB Output is correct
20 Correct 1099 ms 106264 KB Output is correct
21 Correct 1101 ms 105996 KB Output is correct
22 Correct 1114 ms 106148 KB Output is correct
23 Correct 972 ms 106140 KB Output is correct
24 Correct 62 ms 7804 KB Output is correct
25 Correct 57 ms 8532 KB Output is correct
26 Correct 59 ms 9308 KB Output is correct
27 Correct 54 ms 9308 KB Output is correct
28 Correct 61 ms 9364 KB Output is correct
29 Correct 44 ms 8272 KB Output is correct
30 Correct 44 ms 8284 KB Output is correct
31 Correct 59 ms 9176 KB Output is correct
32 Correct 25 ms 3532 KB Output is correct
33 Correct 48 ms 8900 KB Output is correct
34 Correct 158 ms 18772 KB Output is correct
35 Correct 157 ms 21252 KB Output is correct
36 Correct 132 ms 19268 KB Output is correct
37 Correct 137 ms 19152 KB Output is correct
38 Correct 152 ms 19276 KB Output is correct
39 Correct 111 ms 19012 KB Output is correct
40 Correct 120 ms 18880 KB Output is correct
41 Correct 137 ms 20016 KB Output is correct
42 Correct 140 ms 20176 KB Output is correct
43 Correct 122 ms 20264 KB Output is correct
44 Correct 133 ms 21244 KB Output is correct
45 Correct 132 ms 21012 KB Output is correct
46 Correct 137 ms 21184 KB Output is correct
47 Correct 126 ms 21076 KB Output is correct
48 Correct 128 ms 21072 KB Output is correct
49 Correct 115 ms 18776 KB Output is correct
50 Correct 103 ms 18748 KB Output is correct
51 Correct 101 ms 18440 KB Output is correct
52 Correct 104 ms 18512 KB Output is correct
53 Correct 100 ms 18768 KB Output is correct
54 Correct 120 ms 19412 KB Output is correct
55 Correct 101 ms 15304 KB Output is correct
56 Correct 112 ms 19144 KB Output is correct
57 Correct 1254 ms 105084 KB Output is correct
58 Correct 1114 ms 104844 KB Output is correct
59 Correct 1020 ms 100688 KB Output is correct
60 Correct 1047 ms 100688 KB Output is correct
61 Correct 964 ms 100660 KB Output is correct
62 Correct 914 ms 100860 KB Output is correct
63 Correct 598 ms 93012 KB Output is correct
64 Correct 608 ms 93112 KB Output is correct
65 Correct 784 ms 100536 KB Output is correct
66 Correct 791 ms 100112 KB Output is correct
67 Correct 879 ms 100476 KB Output is correct
68 Correct 952 ms 105060 KB Output is correct
69 Correct 921 ms 104924 KB Output is correct
70 Correct 952 ms 104528 KB Output is correct
71 Correct 1046 ms 104108 KB Output is correct
72 Correct 933 ms 104124 KB Output is correct
73 Correct 569 ms 91212 KB Output is correct
74 Correct 536 ms 91904 KB Output is correct
75 Correct 527 ms 91048 KB Output is correct
76 Correct 550 ms 90996 KB Output is correct
77 Correct 563 ms 91216 KB Output is correct
78 Correct 862 ms 97096 KB Output is correct
79 Correct 579 ms 69588 KB Output is correct
80 Correct 811 ms 94876 KB Output is correct