#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const int L = 20;
int n, m;
int w[N], rx[L][N];
int mx[L][N], lg2[N];
int mxr[L][N];
int rmx(int l, int r) {
int w = lg2[r - l + 1];
return max(mx[w][l], mx[w][r - (1 << w) + 1]);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
for (int i = 2; i < N; i++) {
lg2[i] = lg2[i >> 1] + 1;
}
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> w[i];
mx[0][i] = w[i];
}
stack<int> st;
for (int i = n; i >= 1; i--) {
while (!st.empty() && w[i] > w[st.top()]) {
st.pop();
}
rx[0][i] = (st.empty() ? n + 1 : st.top());
st.push(i);
}
rx[0][n + 1] = n + 1;
for (int j = 1; j < L; j++) {
for (int i = 1; i <= n + 1; i++) {
rx[j][i] = rx[j - 1][rx[j - 1][i]];
}
for (int i = 1; i + (1 << j) - 1 <= n; i++) {
mx[j][i] = max(mx[j - 1][i], mx[j - 1][i + (1 << (j - 1))]);
}
}
for (int i = 1; i <= n + 1; i++) {
if (rx[0][i] > i + 1) {
mxr[0][i] = w[i] + rmx(i + 1, rx[0][i] - 1);
}
}
for (int j = 1; j < L; j++) {
for (int i = 1; i <= n + 1; i++) {
mxr[j][i] = max(mxr[j - 1][i], mxr[j - 1][rx[j - 1][i]]);
}
}
while (m--) {
int l, r, k;
cin >> l >> r >> k;
bool f = true;
for (int i = L - 1; i >= 0; i--) {
if (rx[i][l] <= r) {
f &= (mxr[i][l] <= k);
l = rx[i][l];
}
}
if (l < r) {
f &= (w[l] + rmx(l + 1, r) <= k);
}
cout << f << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
90456 KB |
Output is correct |
2 |
Correct |
11 ms |
86364 KB |
Output is correct |
3 |
Correct |
16 ms |
100700 KB |
Output is correct |
4 |
Correct |
12 ms |
96652 KB |
Output is correct |
5 |
Correct |
12 ms |
100756 KB |
Output is correct |
6 |
Correct |
14 ms |
102748 KB |
Output is correct |
7 |
Correct |
13 ms |
102748 KB |
Output is correct |
8 |
Correct |
13 ms |
102864 KB |
Output is correct |
9 |
Correct |
13 ms |
102748 KB |
Output is correct |
10 |
Correct |
14 ms |
102708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
90456 KB |
Output is correct |
2 |
Correct |
11 ms |
86364 KB |
Output is correct |
3 |
Correct |
16 ms |
100700 KB |
Output is correct |
4 |
Correct |
12 ms |
96652 KB |
Output is correct |
5 |
Correct |
12 ms |
100756 KB |
Output is correct |
6 |
Correct |
14 ms |
102748 KB |
Output is correct |
7 |
Correct |
13 ms |
102748 KB |
Output is correct |
8 |
Correct |
13 ms |
102864 KB |
Output is correct |
9 |
Correct |
13 ms |
102748 KB |
Output is correct |
10 |
Correct |
14 ms |
102708 KB |
Output is correct |
11 |
Correct |
16 ms |
106956 KB |
Output is correct |
12 |
Correct |
17 ms |
111252 KB |
Output is correct |
13 |
Correct |
15 ms |
111148 KB |
Output is correct |
14 |
Correct |
15 ms |
111196 KB |
Output is correct |
15 |
Correct |
16 ms |
111144 KB |
Output is correct |
16 |
Correct |
16 ms |
111448 KB |
Output is correct |
17 |
Correct |
19 ms |
111208 KB |
Output is correct |
18 |
Correct |
15 ms |
111124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
982 ms |
262144 KB |
Output is correct |
2 |
Correct |
1050 ms |
262144 KB |
Output is correct |
3 |
Correct |
960 ms |
262144 KB |
Output is correct |
4 |
Correct |
1010 ms |
262144 KB |
Output is correct |
5 |
Correct |
2611 ms |
262144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
146252 KB |
Output is correct |
2 |
Correct |
58 ms |
146192 KB |
Output is correct |
3 |
Correct |
79 ms |
144464 KB |
Output is correct |
4 |
Correct |
85 ms |
144468 KB |
Output is correct |
5 |
Correct |
84 ms |
144468 KB |
Output is correct |
6 |
Correct |
59 ms |
146256 KB |
Output is correct |
7 |
Correct |
57 ms |
146260 KB |
Output is correct |
8 |
Correct |
80 ms |
145968 KB |
Output is correct |
9 |
Correct |
37 ms |
106324 KB |
Output is correct |
10 |
Correct |
67 ms |
146004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
90456 KB |
Output is correct |
2 |
Correct |
11 ms |
86364 KB |
Output is correct |
3 |
Correct |
16 ms |
100700 KB |
Output is correct |
4 |
Correct |
12 ms |
96652 KB |
Output is correct |
5 |
Correct |
12 ms |
100756 KB |
Output is correct |
6 |
Correct |
14 ms |
102748 KB |
Output is correct |
7 |
Correct |
13 ms |
102748 KB |
Output is correct |
8 |
Correct |
13 ms |
102864 KB |
Output is correct |
9 |
Correct |
13 ms |
102748 KB |
Output is correct |
10 |
Correct |
14 ms |
102708 KB |
Output is correct |
11 |
Correct |
16 ms |
106956 KB |
Output is correct |
12 |
Correct |
17 ms |
111252 KB |
Output is correct |
13 |
Correct |
15 ms |
111148 KB |
Output is correct |
14 |
Correct |
15 ms |
111196 KB |
Output is correct |
15 |
Correct |
16 ms |
111144 KB |
Output is correct |
16 |
Correct |
16 ms |
111448 KB |
Output is correct |
17 |
Correct |
19 ms |
111208 KB |
Output is correct |
18 |
Correct |
15 ms |
111124 KB |
Output is correct |
19 |
Correct |
167 ms |
177812 KB |
Output is correct |
20 |
Correct |
163 ms |
177724 KB |
Output is correct |
21 |
Correct |
110 ms |
177504 KB |
Output is correct |
22 |
Correct |
116 ms |
177572 KB |
Output is correct |
23 |
Correct |
114 ms |
177492 KB |
Output is correct |
24 |
Correct |
137 ms |
176060 KB |
Output is correct |
25 |
Correct |
149 ms |
175956 KB |
Output is correct |
26 |
Correct |
167 ms |
176216 KB |
Output is correct |
27 |
Correct |
169 ms |
176408 KB |
Output is correct |
28 |
Correct |
178 ms |
176208 KB |
Output is correct |
29 |
Correct |
267 ms |
176212 KB |
Output is correct |
30 |
Correct |
242 ms |
176208 KB |
Output is correct |
31 |
Correct |
241 ms |
176204 KB |
Output is correct |
32 |
Correct |
261 ms |
176388 KB |
Output is correct |
33 |
Correct |
257 ms |
176392 KB |
Output is correct |
34 |
Correct |
111 ms |
177860 KB |
Output is correct |
35 |
Correct |
116 ms |
178124 KB |
Output is correct |
36 |
Correct |
128 ms |
177772 KB |
Output is correct |
37 |
Correct |
118 ms |
177680 KB |
Output is correct |
38 |
Correct |
118 ms |
178004 KB |
Output is correct |
39 |
Correct |
203 ms |
176588 KB |
Output is correct |
40 |
Correct |
140 ms |
155216 KB |
Output is correct |
41 |
Correct |
158 ms |
175968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
90456 KB |
Output is correct |
2 |
Correct |
11 ms |
86364 KB |
Output is correct |
3 |
Correct |
16 ms |
100700 KB |
Output is correct |
4 |
Correct |
12 ms |
96652 KB |
Output is correct |
5 |
Correct |
12 ms |
100756 KB |
Output is correct |
6 |
Correct |
14 ms |
102748 KB |
Output is correct |
7 |
Correct |
13 ms |
102748 KB |
Output is correct |
8 |
Correct |
13 ms |
102864 KB |
Output is correct |
9 |
Correct |
13 ms |
102748 KB |
Output is correct |
10 |
Correct |
14 ms |
102708 KB |
Output is correct |
11 |
Correct |
16 ms |
106956 KB |
Output is correct |
12 |
Correct |
17 ms |
111252 KB |
Output is correct |
13 |
Correct |
15 ms |
111148 KB |
Output is correct |
14 |
Correct |
15 ms |
111196 KB |
Output is correct |
15 |
Correct |
16 ms |
111144 KB |
Output is correct |
16 |
Correct |
16 ms |
111448 KB |
Output is correct |
17 |
Correct |
19 ms |
111208 KB |
Output is correct |
18 |
Correct |
15 ms |
111124 KB |
Output is correct |
19 |
Correct |
982 ms |
262144 KB |
Output is correct |
20 |
Correct |
1050 ms |
262144 KB |
Output is correct |
21 |
Correct |
960 ms |
262144 KB |
Output is correct |
22 |
Correct |
1010 ms |
262144 KB |
Output is correct |
23 |
Correct |
2611 ms |
262144 KB |
Output is correct |
24 |
Correct |
64 ms |
146252 KB |
Output is correct |
25 |
Correct |
58 ms |
146192 KB |
Output is correct |
26 |
Correct |
79 ms |
144464 KB |
Output is correct |
27 |
Correct |
85 ms |
144468 KB |
Output is correct |
28 |
Correct |
84 ms |
144468 KB |
Output is correct |
29 |
Correct |
59 ms |
146256 KB |
Output is correct |
30 |
Correct |
57 ms |
146260 KB |
Output is correct |
31 |
Correct |
80 ms |
145968 KB |
Output is correct |
32 |
Correct |
37 ms |
106324 KB |
Output is correct |
33 |
Correct |
67 ms |
146004 KB |
Output is correct |
34 |
Correct |
167 ms |
177812 KB |
Output is correct |
35 |
Correct |
163 ms |
177724 KB |
Output is correct |
36 |
Correct |
110 ms |
177504 KB |
Output is correct |
37 |
Correct |
116 ms |
177572 KB |
Output is correct |
38 |
Correct |
114 ms |
177492 KB |
Output is correct |
39 |
Correct |
137 ms |
176060 KB |
Output is correct |
40 |
Correct |
149 ms |
175956 KB |
Output is correct |
41 |
Correct |
167 ms |
176216 KB |
Output is correct |
42 |
Correct |
169 ms |
176408 KB |
Output is correct |
43 |
Correct |
178 ms |
176208 KB |
Output is correct |
44 |
Correct |
267 ms |
176212 KB |
Output is correct |
45 |
Correct |
242 ms |
176208 KB |
Output is correct |
46 |
Correct |
241 ms |
176204 KB |
Output is correct |
47 |
Correct |
261 ms |
176388 KB |
Output is correct |
48 |
Correct |
257 ms |
176392 KB |
Output is correct |
49 |
Correct |
111 ms |
177860 KB |
Output is correct |
50 |
Correct |
116 ms |
178124 KB |
Output is correct |
51 |
Correct |
128 ms |
177772 KB |
Output is correct |
52 |
Correct |
118 ms |
177680 KB |
Output is correct |
53 |
Correct |
118 ms |
178004 KB |
Output is correct |
54 |
Correct |
203 ms |
176588 KB |
Output is correct |
55 |
Correct |
140 ms |
155216 KB |
Output is correct |
56 |
Correct |
158 ms |
175968 KB |
Output is correct |
57 |
Runtime error |
1070 ms |
262148 KB |
Memory limit exceeded |
58 |
Halted |
0 ms |
0 KB |
- |