Submission #973404

# Submission time Handle Problem Language Result Execution time Memory
973404 2024-05-01T23:13:38 Z colossal_pepe Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
923 ms 98416 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 idx, int x) {
		for (tree[idx += n] = x; idx > 1; idx /= 2) {
			tree[idx / 2] = max(tree[idx], tree[idx^1]);
		}
	}
	int query(int l, int r) {
		int ret = 0;
		for (l += n, r += n; l <= r; l /= 2, r /= 2) {
			if (l % 2) ret = max(ret, tree[l++]);
			if (not (r % 2)) ret = max(ret, tree[r--]);
		}
		return ret;
	}
};

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(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(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 1 ms 348 KB Output is correct
3 Correct 1 ms 460 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 0 ms 348 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 1 ms 348 KB Output is correct
3 Correct 1 ms 460 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 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 724 KB Output is correct
13 Correct 2 ms 728 KB Output is correct
14 Correct 3 ms 860 KB Output is correct
15 Correct 3 ms 860 KB Output is correct
16 Correct 3 ms 1112 KB Output is correct
17 Correct 2 ms 860 KB Output is correct
18 Correct 2 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 923 ms 97520 KB Output is correct
2 Correct 919 ms 98352 KB Output is correct
3 Correct 874 ms 97872 KB Output is correct
4 Correct 880 ms 98416 KB Output is correct
5 Correct 904 ms 98288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 9296 KB Output is correct
2 Correct 47 ms 8532 KB Output is correct
3 Correct 47 ms 9044 KB Output is correct
4 Correct 56 ms 9052 KB Output is correct
5 Correct 61 ms 9300 KB Output is correct
6 Correct 37 ms 8336 KB Output is correct
7 Correct 36 ms 8276 KB Output is correct
8 Correct 43 ms 8908 KB Output is correct
9 Correct 25 ms 3600 KB Output is correct
10 Correct 43 ms 8916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 460 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 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 724 KB Output is correct
13 Correct 2 ms 728 KB Output is correct
14 Correct 3 ms 860 KB Output is correct
15 Correct 3 ms 860 KB Output is correct
16 Correct 3 ms 1112 KB Output is correct
17 Correct 2 ms 860 KB Output is correct
18 Correct 2 ms 860 KB Output is correct
19 Correct 120 ms 20140 KB Output is correct
20 Correct 116 ms 19792 KB Output is correct
21 Correct 108 ms 18208 KB Output is correct
22 Correct 113 ms 18252 KB Output is correct
23 Correct 104 ms 18260 KB Output is correct
24 Correct 95 ms 17872 KB Output is correct
25 Correct 101 ms 18000 KB Output is correct
26 Correct 104 ms 18772 KB Output is correct
27 Correct 106 ms 18828 KB Output is correct
28 Correct 129 ms 18980 KB Output is correct
29 Correct 141 ms 19960 KB Output is correct
30 Correct 129 ms 19796 KB Output is correct
31 Correct 115 ms 19704 KB Output is correct
32 Correct 112 ms 19876 KB Output is correct
33 Correct 114 ms 19964 KB Output is correct
34 Correct 90 ms 17544 KB Output is correct
35 Correct 88 ms 17488 KB Output is correct
36 Correct 98 ms 17352 KB Output is correct
37 Correct 87 ms 17232 KB Output is correct
38 Correct 90 ms 17616 KB Output is correct
39 Correct 98 ms 18640 KB Output is correct
40 Correct 79 ms 14796 KB Output is correct
41 Correct 116 ms 18052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 460 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 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 724 KB Output is correct
13 Correct 2 ms 728 KB Output is correct
14 Correct 3 ms 860 KB Output is correct
15 Correct 3 ms 860 KB Output is correct
16 Correct 3 ms 1112 KB Output is correct
17 Correct 2 ms 860 KB Output is correct
18 Correct 2 ms 860 KB Output is correct
19 Correct 923 ms 97520 KB Output is correct
20 Correct 919 ms 98352 KB Output is correct
21 Correct 874 ms 97872 KB Output is correct
22 Correct 880 ms 98416 KB Output is correct
23 Correct 904 ms 98288 KB Output is correct
24 Correct 48 ms 9296 KB Output is correct
25 Correct 47 ms 8532 KB Output is correct
26 Correct 47 ms 9044 KB Output is correct
27 Correct 56 ms 9052 KB Output is correct
28 Correct 61 ms 9300 KB Output is correct
29 Correct 37 ms 8336 KB Output is correct
30 Correct 36 ms 8276 KB Output is correct
31 Correct 43 ms 8908 KB Output is correct
32 Correct 25 ms 3600 KB Output is correct
33 Correct 43 ms 8916 KB Output is correct
34 Correct 120 ms 20140 KB Output is correct
35 Correct 116 ms 19792 KB Output is correct
36 Correct 108 ms 18208 KB Output is correct
37 Correct 113 ms 18252 KB Output is correct
38 Correct 104 ms 18260 KB Output is correct
39 Correct 95 ms 17872 KB Output is correct
40 Correct 101 ms 18000 KB Output is correct
41 Correct 104 ms 18772 KB Output is correct
42 Correct 106 ms 18828 KB Output is correct
43 Correct 129 ms 18980 KB Output is correct
44 Correct 141 ms 19960 KB Output is correct
45 Correct 129 ms 19796 KB Output is correct
46 Correct 115 ms 19704 KB Output is correct
47 Correct 112 ms 19876 KB Output is correct
48 Correct 114 ms 19964 KB Output is correct
49 Correct 90 ms 17544 KB Output is correct
50 Correct 88 ms 17488 KB Output is correct
51 Correct 98 ms 17352 KB Output is correct
52 Correct 87 ms 17232 KB Output is correct
53 Correct 90 ms 17616 KB Output is correct
54 Correct 98 ms 18640 KB Output is correct
55 Correct 79 ms 14796 KB Output is correct
56 Correct 116 ms 18052 KB Output is correct
57 Correct 913 ms 88372 KB Output is correct
58 Correct 909 ms 88348 KB Output is correct
59 Correct 757 ms 84376 KB Output is correct
60 Correct 847 ms 84208 KB Output is correct
61 Correct 792 ms 84268 KB Output is correct
62 Correct 751 ms 84356 KB Output is correct
63 Correct 476 ms 77688 KB Output is correct
64 Correct 528 ms 77676 KB Output is correct
65 Correct 735 ms 83744 KB Output is correct
66 Correct 735 ms 83736 KB Output is correct
67 Correct 727 ms 84056 KB Output is correct
68 Correct 873 ms 88356 KB Output is correct
69 Correct 842 ms 88408 KB Output is correct
70 Correct 838 ms 87652 KB Output is correct
71 Correct 815 ms 87656 KB Output is correct
72 Correct 805 ms 87376 KB Output is correct
73 Correct 431 ms 76628 KB Output is correct
74 Correct 432 ms 76848 KB Output is correct
75 Correct 459 ms 76372 KB Output is correct
76 Correct 439 ms 84052 KB Output is correct
77 Correct 434 ms 76332 KB Output is correct
78 Correct 719 ms 83468 KB Output is correct
79 Correct 520 ms 58144 KB Output is correct
80 Correct 669 ms 82532 KB Output is correct