답안 #990750

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
990750 2024-05-31T07:13:38 Z perchuts Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
2315 ms 65916 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e6 + 5;


int seg[4*maxn], w[maxn];

void upd(int i, int l, int r, int x, int k) {
	if (l == r) {
		seg[i] = max(seg[i], k + w[l]);
		return;
	}
	int md = (l + r) / 2;
	if (x <= md) upd(2*i, l, md, x, k);
	else upd(2*i+1, md+1, r, x, k);
	seg[i] = max(seg[2*i], seg[2*i+1]);
}

int query(int i, int l, int r, int x, int y) {
	if (r < x || y < l) return 0;
	if (x <= l && r <= y) return seg[i];
	int md = (l + r) / 2;
	return max(query(2*i, l, md, x, y), query(2*i+1, md+1, r, x, y));
}

int main() {
	int n, q, xx = 0; cin >> n >> q;
	for (int i = 1; i <= n; ++i) cin >> w[i];
	using iii = tuple<int,int,int, int>;
	vector<iii> queries(q);
	for (auto& [r, l, k, id] : queries) cin >> l >> r >> k, id = xx++;
	sort(begin(queries), end(queries));
	vector<int> ans(q);
	int pt = 1;
	stack<int> st;
	for (auto [r, l, k, id] : queries) {
		while (pt <= r) {
			while (!st.empty() && w[st.top()] <= w[pt]) st.pop();
			if (!st.empty()) {
				upd(1, 1, n, st.top(), w[pt]);
			}
			st.push(pt++);
		}
		ans[id] = (query(1, 1, n, l, r) <= k);
	}
	for (int i = 0; i < q; ++i) cout << ans[i] << endl;
}
# 결과 실행 시간 메모리 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 1 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 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 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 1 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 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 6 ms 608 KB Output is correct
12 Correct 7 ms 600 KB Output is correct
13 Correct 8 ms 600 KB Output is correct
14 Correct 10 ms 684 KB Output is correct
15 Correct 11 ms 600 KB Output is correct
16 Correct 9 ms 604 KB Output is correct
17 Correct 9 ms 604 KB Output is correct
18 Correct 9 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2207 ms 34128 KB Output is correct
2 Correct 2171 ms 65260 KB Output is correct
3 Correct 2201 ms 64924 KB Output is correct
4 Correct 2170 ms 65364 KB Output is correct
5 Correct 2084 ms 57428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 191 ms 7508 KB Output is correct
2 Correct 186 ms 9452 KB Output is correct
3 Correct 178 ms 6740 KB Output is correct
4 Correct 184 ms 6648 KB Output is correct
5 Correct 184 ms 6628 KB Output is correct
6 Correct 175 ms 8528 KB Output is correct
7 Correct 173 ms 8532 KB Output is correct
8 Correct 171 ms 6396 KB Output is correct
9 Correct 149 ms 3848 KB Output is correct
10 Correct 174 ms 6408 KB Output is correct
# 결과 실행 시간 메모리 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 1 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 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 6 ms 608 KB Output is correct
12 Correct 7 ms 600 KB Output is correct
13 Correct 8 ms 600 KB Output is correct
14 Correct 10 ms 684 KB Output is correct
15 Correct 11 ms 600 KB Output is correct
16 Correct 9 ms 604 KB Output is correct
17 Correct 9 ms 604 KB Output is correct
18 Correct 9 ms 604 KB Output is correct
19 Correct 460 ms 17364 KB Output is correct
20 Correct 432 ms 17228 KB Output is correct
21 Correct 437 ms 16980 KB Output is correct
22 Correct 415 ms 17092 KB Output is correct
23 Correct 443 ms 16904 KB Output is correct
24 Correct 411 ms 13140 KB Output is correct
25 Correct 407 ms 13136 KB Output is correct
26 Correct 458 ms 13648 KB Output is correct
27 Correct 420 ms 13248 KB Output is correct
28 Correct 430 ms 13376 KB Output is correct
29 Correct 511 ms 13352 KB Output is correct
30 Correct 444 ms 13520 KB Output is correct
31 Correct 467 ms 13324 KB Output is correct
32 Correct 454 ms 13520 KB Output is correct
33 Correct 444 ms 13652 KB Output is correct
34 Correct 415 ms 15188 KB Output is correct
35 Correct 397 ms 14996 KB Output is correct
36 Correct 396 ms 14932 KB Output is correct
37 Correct 407 ms 14932 KB Output is correct
38 Correct 424 ms 15184 KB Output is correct
39 Correct 402 ms 12880 KB Output is correct
40 Correct 366 ms 11344 KB Output is correct
41 Correct 378 ms 11544 KB Output is correct
# 결과 실행 시간 메모리 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 1 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 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 6 ms 608 KB Output is correct
12 Correct 7 ms 600 KB Output is correct
13 Correct 8 ms 600 KB Output is correct
14 Correct 10 ms 684 KB Output is correct
15 Correct 11 ms 600 KB Output is correct
16 Correct 9 ms 604 KB Output is correct
17 Correct 9 ms 604 KB Output is correct
18 Correct 9 ms 604 KB Output is correct
19 Correct 2207 ms 34128 KB Output is correct
20 Correct 2171 ms 65260 KB Output is correct
21 Correct 2201 ms 64924 KB Output is correct
22 Correct 2170 ms 65364 KB Output is correct
23 Correct 2084 ms 57428 KB Output is correct
24 Correct 191 ms 7508 KB Output is correct
25 Correct 186 ms 9452 KB Output is correct
26 Correct 178 ms 6740 KB Output is correct
27 Correct 184 ms 6648 KB Output is correct
28 Correct 184 ms 6628 KB Output is correct
29 Correct 175 ms 8528 KB Output is correct
30 Correct 173 ms 8532 KB Output is correct
31 Correct 171 ms 6396 KB Output is correct
32 Correct 149 ms 3848 KB Output is correct
33 Correct 174 ms 6408 KB Output is correct
34 Correct 460 ms 17364 KB Output is correct
35 Correct 432 ms 17228 KB Output is correct
36 Correct 437 ms 16980 KB Output is correct
37 Correct 415 ms 17092 KB Output is correct
38 Correct 443 ms 16904 KB Output is correct
39 Correct 411 ms 13140 KB Output is correct
40 Correct 407 ms 13136 KB Output is correct
41 Correct 458 ms 13648 KB Output is correct
42 Correct 420 ms 13248 KB Output is correct
43 Correct 430 ms 13376 KB Output is correct
44 Correct 511 ms 13352 KB Output is correct
45 Correct 444 ms 13520 KB Output is correct
46 Correct 467 ms 13324 KB Output is correct
47 Correct 454 ms 13520 KB Output is correct
48 Correct 444 ms 13652 KB Output is correct
49 Correct 415 ms 15188 KB Output is correct
50 Correct 397 ms 14996 KB Output is correct
51 Correct 396 ms 14932 KB Output is correct
52 Correct 407 ms 14932 KB Output is correct
53 Correct 424 ms 15184 KB Output is correct
54 Correct 402 ms 12880 KB Output is correct
55 Correct 366 ms 11344 KB Output is correct
56 Correct 378 ms 11544 KB Output is correct
57 Correct 2189 ms 65912 KB Output is correct
58 Correct 2315 ms 65732 KB Output is correct
59 Correct 2211 ms 65916 KB Output is correct
60 Correct 2149 ms 65876 KB Output is correct
61 Correct 2182 ms 65888 KB Output is correct
62 Correct 2184 ms 65852 KB Output is correct
63 Correct 2067 ms 56440 KB Output is correct
64 Correct 2080 ms 56400 KB Output is correct
65 Correct 2226 ms 57856 KB Output is correct
66 Correct 2099 ms 57920 KB Output is correct
67 Correct 2110 ms 57940 KB Output is correct
68 Correct 2138 ms 57940 KB Output is correct
69 Correct 2146 ms 58452 KB Output is correct
70 Correct 2154 ms 57924 KB Output is correct
71 Correct 2199 ms 58196 KB Output is correct
72 Correct 2143 ms 57852 KB Output is correct
73 Correct 2037 ms 56912 KB Output is correct
74 Correct 2154 ms 57936 KB Output is correct
75 Correct 1988 ms 55036 KB Output is correct
76 Correct 2058 ms 55124 KB Output is correct
77 Correct 2069 ms 55084 KB Output is correct
78 Correct 2075 ms 53072 KB Output is correct
79 Correct 1842 ms 44372 KB Output is correct
80 Correct 1925 ms 47956 KB Output is correct