#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e6 + 5;
const int MAX_M = 1e6 + 5;
const int INF = 1e9 + 7;
int w[MAX_N];
bool ans[MAX_M];
vector <tuple <int, int, int>> queries[MAX_N];
int tree[4 * MAX_N];
void update(int idx, int l, int r, int q, int v) {
if(l == r) {
tree[idx] = v;
return;
}
int mid = (l + r) / 2;
if(q <= mid) {
update(idx * 2, l, mid, q, v);
}
else {
update(idx * 2 + 1, mid + 1, r, q, v);
}
tree[idx] = max(tree[idx * 2], tree[idx * 2 + 1]);
}
int query(int idx, int l, int r, int ql, int qr) {
if(r < ql or qr < l) {
return 0;
}
if(ql <= l and r <= qr) {
return tree[idx];
}
int mid = (l + r) / 2;
return max(query(idx * 2, l, mid, ql, qr), query(idx * 2 + 1, mid + 1, r, ql, qr));
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N, M;
cin >> N >> M;
for(int i = 1; i <= N; i++) {
cin >> w[i];
}
for(int i = 1; i <= M; i++) {
int l, r, k;
cin >> l >> r >> k;
queries[r].emplace_back(l, i, k);
}
stack <int> stk;
for(int i = 1; i <= N; i++) {
while(!stk.empty() and w[stk.top()] <= w[i]) {
stk.pop();
}
if(!stk.empty()) {
update(1, 1, N, stk.top(), w[stk.top()] + w[i]);
}
stk.push(i);
for(auto [l, id, k] : queries[i]) {
ans[id] = (query(1, 1, N, l, i) <= k);
}
}
for(int i = 1; i <= M; i++) {
cout << ans[i] << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23828 KB |
Output is correct |
3 |
Correct |
15 ms |
23748 KB |
Output is correct |
4 |
Correct |
13 ms |
23764 KB |
Output is correct |
5 |
Correct |
13 ms |
23764 KB |
Output is correct |
6 |
Correct |
13 ms |
23852 KB |
Output is correct |
7 |
Correct |
13 ms |
23852 KB |
Output is correct |
8 |
Correct |
13 ms |
23804 KB |
Output is correct |
9 |
Correct |
13 ms |
23764 KB |
Output is correct |
10 |
Correct |
12 ms |
23764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23828 KB |
Output is correct |
3 |
Correct |
15 ms |
23748 KB |
Output is correct |
4 |
Correct |
13 ms |
23764 KB |
Output is correct |
5 |
Correct |
13 ms |
23764 KB |
Output is correct |
6 |
Correct |
13 ms |
23852 KB |
Output is correct |
7 |
Correct |
13 ms |
23852 KB |
Output is correct |
8 |
Correct |
13 ms |
23804 KB |
Output is correct |
9 |
Correct |
13 ms |
23764 KB |
Output is correct |
10 |
Correct |
12 ms |
23764 KB |
Output is correct |
11 |
Correct |
15 ms |
23900 KB |
Output is correct |
12 |
Correct |
19 ms |
23892 KB |
Output is correct |
13 |
Correct |
19 ms |
23984 KB |
Output is correct |
14 |
Correct |
19 ms |
24044 KB |
Output is correct |
15 |
Correct |
20 ms |
23964 KB |
Output is correct |
16 |
Correct |
16 ms |
23892 KB |
Output is correct |
17 |
Correct |
15 ms |
23892 KB |
Output is correct |
18 |
Correct |
15 ms |
24000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1314 ms |
60624 KB |
Output is correct |
2 |
Correct |
1223 ms |
60652 KB |
Output is correct |
3 |
Correct |
1272 ms |
60652 KB |
Output is correct |
4 |
Correct |
1400 ms |
60800 KB |
Output is correct |
5 |
Correct |
1247 ms |
52428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
93 ms |
27596 KB |
Output is correct |
2 |
Correct |
116 ms |
29356 KB |
Output is correct |
3 |
Correct |
126 ms |
28436 KB |
Output is correct |
4 |
Correct |
103 ms |
28504 KB |
Output is correct |
5 |
Correct |
90 ms |
28540 KB |
Output is correct |
6 |
Correct |
74 ms |
28040 KB |
Output is correct |
7 |
Correct |
72 ms |
28012 KB |
Output is correct |
8 |
Correct |
84 ms |
28108 KB |
Output is correct |
9 |
Correct |
56 ms |
26920 KB |
Output is correct |
10 |
Correct |
97 ms |
28168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23828 KB |
Output is correct |
3 |
Correct |
15 ms |
23748 KB |
Output is correct |
4 |
Correct |
13 ms |
23764 KB |
Output is correct |
5 |
Correct |
13 ms |
23764 KB |
Output is correct |
6 |
Correct |
13 ms |
23852 KB |
Output is correct |
7 |
Correct |
13 ms |
23852 KB |
Output is correct |
8 |
Correct |
13 ms |
23804 KB |
Output is correct |
9 |
Correct |
13 ms |
23764 KB |
Output is correct |
10 |
Correct |
12 ms |
23764 KB |
Output is correct |
11 |
Correct |
15 ms |
23900 KB |
Output is correct |
12 |
Correct |
19 ms |
23892 KB |
Output is correct |
13 |
Correct |
19 ms |
23984 KB |
Output is correct |
14 |
Correct |
19 ms |
24044 KB |
Output is correct |
15 |
Correct |
20 ms |
23964 KB |
Output is correct |
16 |
Correct |
16 ms |
23892 KB |
Output is correct |
17 |
Correct |
15 ms |
23892 KB |
Output is correct |
18 |
Correct |
15 ms |
24000 KB |
Output is correct |
19 |
Correct |
242 ms |
32464 KB |
Output is correct |
20 |
Correct |
240 ms |
38028 KB |
Output is correct |
21 |
Correct |
198 ms |
37400 KB |
Output is correct |
22 |
Correct |
215 ms |
37396 KB |
Output is correct |
23 |
Correct |
234 ms |
37388 KB |
Output is correct |
24 |
Correct |
167 ms |
35192 KB |
Output is correct |
25 |
Correct |
183 ms |
35140 KB |
Output is correct |
26 |
Correct |
208 ms |
35536 KB |
Output is correct |
27 |
Correct |
238 ms |
35496 KB |
Output is correct |
28 |
Correct |
240 ms |
35640 KB |
Output is correct |
29 |
Correct |
215 ms |
35960 KB |
Output is correct |
30 |
Correct |
202 ms |
36024 KB |
Output is correct |
31 |
Correct |
224 ms |
35988 KB |
Output is correct |
32 |
Correct |
193 ms |
36012 KB |
Output is correct |
33 |
Correct |
208 ms |
35968 KB |
Output is correct |
34 |
Correct |
148 ms |
34808 KB |
Output is correct |
35 |
Correct |
146 ms |
34740 KB |
Output is correct |
36 |
Correct |
145 ms |
34576 KB |
Output is correct |
37 |
Correct |
163 ms |
34588 KB |
Output is correct |
38 |
Correct |
157 ms |
34700 KB |
Output is correct |
39 |
Correct |
165 ms |
34892 KB |
Output is correct |
40 |
Correct |
150 ms |
32976 KB |
Output is correct |
41 |
Correct |
179 ms |
33872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23828 KB |
Output is correct |
3 |
Correct |
15 ms |
23748 KB |
Output is correct |
4 |
Correct |
13 ms |
23764 KB |
Output is correct |
5 |
Correct |
13 ms |
23764 KB |
Output is correct |
6 |
Correct |
13 ms |
23852 KB |
Output is correct |
7 |
Correct |
13 ms |
23852 KB |
Output is correct |
8 |
Correct |
13 ms |
23804 KB |
Output is correct |
9 |
Correct |
13 ms |
23764 KB |
Output is correct |
10 |
Correct |
12 ms |
23764 KB |
Output is correct |
11 |
Correct |
15 ms |
23900 KB |
Output is correct |
12 |
Correct |
19 ms |
23892 KB |
Output is correct |
13 |
Correct |
19 ms |
23984 KB |
Output is correct |
14 |
Correct |
19 ms |
24044 KB |
Output is correct |
15 |
Correct |
20 ms |
23964 KB |
Output is correct |
16 |
Correct |
16 ms |
23892 KB |
Output is correct |
17 |
Correct |
15 ms |
23892 KB |
Output is correct |
18 |
Correct |
15 ms |
24000 KB |
Output is correct |
19 |
Correct |
1314 ms |
60624 KB |
Output is correct |
20 |
Correct |
1223 ms |
60652 KB |
Output is correct |
21 |
Correct |
1272 ms |
60652 KB |
Output is correct |
22 |
Correct |
1400 ms |
60800 KB |
Output is correct |
23 |
Correct |
1247 ms |
52428 KB |
Output is correct |
24 |
Correct |
93 ms |
27596 KB |
Output is correct |
25 |
Correct |
116 ms |
29356 KB |
Output is correct |
26 |
Correct |
126 ms |
28436 KB |
Output is correct |
27 |
Correct |
103 ms |
28504 KB |
Output is correct |
28 |
Correct |
90 ms |
28540 KB |
Output is correct |
29 |
Correct |
74 ms |
28040 KB |
Output is correct |
30 |
Correct |
72 ms |
28012 KB |
Output is correct |
31 |
Correct |
84 ms |
28108 KB |
Output is correct |
32 |
Correct |
56 ms |
26920 KB |
Output is correct |
33 |
Correct |
97 ms |
28168 KB |
Output is correct |
34 |
Correct |
242 ms |
32464 KB |
Output is correct |
35 |
Correct |
240 ms |
38028 KB |
Output is correct |
36 |
Correct |
198 ms |
37400 KB |
Output is correct |
37 |
Correct |
215 ms |
37396 KB |
Output is correct |
38 |
Correct |
234 ms |
37388 KB |
Output is correct |
39 |
Correct |
167 ms |
35192 KB |
Output is correct |
40 |
Correct |
183 ms |
35140 KB |
Output is correct |
41 |
Correct |
208 ms |
35536 KB |
Output is correct |
42 |
Correct |
238 ms |
35496 KB |
Output is correct |
43 |
Correct |
240 ms |
35640 KB |
Output is correct |
44 |
Correct |
215 ms |
35960 KB |
Output is correct |
45 |
Correct |
202 ms |
36024 KB |
Output is correct |
46 |
Correct |
224 ms |
35988 KB |
Output is correct |
47 |
Correct |
193 ms |
36012 KB |
Output is correct |
48 |
Correct |
208 ms |
35968 KB |
Output is correct |
49 |
Correct |
148 ms |
34808 KB |
Output is correct |
50 |
Correct |
146 ms |
34740 KB |
Output is correct |
51 |
Correct |
145 ms |
34576 KB |
Output is correct |
52 |
Correct |
163 ms |
34588 KB |
Output is correct |
53 |
Correct |
157 ms |
34700 KB |
Output is correct |
54 |
Correct |
165 ms |
34892 KB |
Output is correct |
55 |
Correct |
150 ms |
32976 KB |
Output is correct |
56 |
Correct |
179 ms |
33872 KB |
Output is correct |
57 |
Correct |
1312 ms |
93640 KB |
Output is correct |
58 |
Correct |
1243 ms |
93732 KB |
Output is correct |
59 |
Correct |
1210 ms |
92148 KB |
Output is correct |
60 |
Correct |
1226 ms |
92280 KB |
Output is correct |
61 |
Correct |
1125 ms |
92172 KB |
Output is correct |
62 |
Correct |
1114 ms |
92128 KB |
Output is correct |
63 |
Correct |
792 ms |
80688 KB |
Output is correct |
64 |
Correct |
802 ms |
80644 KB |
Output is correct |
65 |
Correct |
1049 ms |
83792 KB |
Output is correct |
66 |
Correct |
1002 ms |
83724 KB |
Output is correct |
67 |
Correct |
1006 ms |
83984 KB |
Output is correct |
68 |
Correct |
1069 ms |
85440 KB |
Output is correct |
69 |
Correct |
1032 ms |
85476 KB |
Output is correct |
70 |
Correct |
1092 ms |
85160 KB |
Output is correct |
71 |
Correct |
1097 ms |
85184 KB |
Output is correct |
72 |
Correct |
1063 ms |
85160 KB |
Output is correct |
73 |
Correct |
736 ms |
76524 KB |
Output is correct |
74 |
Correct |
760 ms |
77532 KB |
Output is correct |
75 |
Correct |
781 ms |
76596 KB |
Output is correct |
76 |
Correct |
906 ms |
76900 KB |
Output is correct |
77 |
Correct |
895 ms |
76400 KB |
Output is correct |
78 |
Correct |
1105 ms |
80252 KB |
Output is correct |
79 |
Correct |
798 ms |
68704 KB |
Output is correct |
80 |
Correct |
1101 ms |
74748 KB |
Output is correct |