#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 2;
const int L = 20;
int n, m;
int rx[L][N];
int mx[L][N];
int mxr[L][N];
int rmx(int l, int r) {
int w = __lg(r - l + 1);
return max(mx[w][l], mx[w][r - (1 << w) + 1]);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> mx[0][i];
}
stack<int> st;
for (int i = n; i >= 1; i--) {
while (!st.empty() && mx[0][i] > mx[0][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] = mx[0][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 &= (mx[0][l] + rmx(l + 1, r) <= k);
}
cout << f << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
86620 KB |
Output is correct |
2 |
Correct |
8 ms |
82520 KB |
Output is correct |
3 |
Correct |
11 ms |
96860 KB |
Output is correct |
4 |
Correct |
10 ms |
92764 KB |
Output is correct |
5 |
Correct |
10 ms |
96860 KB |
Output is correct |
6 |
Correct |
12 ms |
98960 KB |
Output is correct |
7 |
Correct |
11 ms |
98908 KB |
Output is correct |
8 |
Correct |
11 ms |
98908 KB |
Output is correct |
9 |
Correct |
11 ms |
98904 KB |
Output is correct |
10 |
Correct |
11 ms |
98908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
86620 KB |
Output is correct |
2 |
Correct |
8 ms |
82520 KB |
Output is correct |
3 |
Correct |
11 ms |
96860 KB |
Output is correct |
4 |
Correct |
10 ms |
92764 KB |
Output is correct |
5 |
Correct |
10 ms |
96860 KB |
Output is correct |
6 |
Correct |
12 ms |
98960 KB |
Output is correct |
7 |
Correct |
11 ms |
98908 KB |
Output is correct |
8 |
Correct |
11 ms |
98908 KB |
Output is correct |
9 |
Correct |
11 ms |
98904 KB |
Output is correct |
10 |
Correct |
11 ms |
98908 KB |
Output is correct |
11 |
Correct |
13 ms |
103004 KB |
Output is correct |
12 |
Correct |
14 ms |
107104 KB |
Output is correct |
13 |
Correct |
15 ms |
107100 KB |
Output is correct |
14 |
Correct |
14 ms |
107100 KB |
Output is correct |
15 |
Correct |
14 ms |
107100 KB |
Output is correct |
16 |
Correct |
14 ms |
107064 KB |
Output is correct |
17 |
Correct |
13 ms |
107100 KB |
Output is correct |
18 |
Correct |
14 ms |
107100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
870 ms |
237168 KB |
Output is correct |
2 |
Correct |
863 ms |
237244 KB |
Output is correct |
3 |
Correct |
849 ms |
237136 KB |
Output is correct |
4 |
Correct |
852 ms |
237256 KB |
Output is correct |
5 |
Correct |
2501 ms |
239380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
140260 KB |
Output is correct |
2 |
Correct |
54 ms |
140224 KB |
Output is correct |
3 |
Correct |
72 ms |
138320 KB |
Output is correct |
4 |
Correct |
102 ms |
138436 KB |
Output is correct |
5 |
Correct |
90 ms |
138332 KB |
Output is correct |
6 |
Correct |
54 ms |
140368 KB |
Output is correct |
7 |
Correct |
55 ms |
140380 KB |
Output is correct |
8 |
Correct |
62 ms |
140120 KB |
Output is correct |
9 |
Correct |
35 ms |
100956 KB |
Output is correct |
10 |
Correct |
63 ms |
140372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
86620 KB |
Output is correct |
2 |
Correct |
8 ms |
82520 KB |
Output is correct |
3 |
Correct |
11 ms |
96860 KB |
Output is correct |
4 |
Correct |
10 ms |
92764 KB |
Output is correct |
5 |
Correct |
10 ms |
96860 KB |
Output is correct |
6 |
Correct |
12 ms |
98960 KB |
Output is correct |
7 |
Correct |
11 ms |
98908 KB |
Output is correct |
8 |
Correct |
11 ms |
98908 KB |
Output is correct |
9 |
Correct |
11 ms |
98904 KB |
Output is correct |
10 |
Correct |
11 ms |
98908 KB |
Output is correct |
11 |
Correct |
13 ms |
103004 KB |
Output is correct |
12 |
Correct |
14 ms |
107104 KB |
Output is correct |
13 |
Correct |
15 ms |
107100 KB |
Output is correct |
14 |
Correct |
14 ms |
107100 KB |
Output is correct |
15 |
Correct |
14 ms |
107100 KB |
Output is correct |
16 |
Correct |
14 ms |
107064 KB |
Output is correct |
17 |
Correct |
13 ms |
107100 KB |
Output is correct |
18 |
Correct |
14 ms |
107100 KB |
Output is correct |
19 |
Correct |
156 ms |
164992 KB |
Output is correct |
20 |
Correct |
159 ms |
165168 KB |
Output is correct |
21 |
Correct |
102 ms |
164944 KB |
Output is correct |
22 |
Correct |
106 ms |
164944 KB |
Output is correct |
23 |
Correct |
105 ms |
165040 KB |
Output is correct |
24 |
Correct |
126 ms |
163668 KB |
Output is correct |
25 |
Correct |
132 ms |
163592 KB |
Output is correct |
26 |
Correct |
168 ms |
163740 KB |
Output is correct |
27 |
Correct |
155 ms |
163600 KB |
Output is correct |
28 |
Correct |
183 ms |
163688 KB |
Output is correct |
29 |
Correct |
243 ms |
163664 KB |
Output is correct |
30 |
Correct |
233 ms |
163664 KB |
Output is correct |
31 |
Correct |
243 ms |
163600 KB |
Output is correct |
32 |
Correct |
289 ms |
163684 KB |
Output is correct |
33 |
Correct |
236 ms |
163664 KB |
Output is correct |
34 |
Correct |
108 ms |
165728 KB |
Output is correct |
35 |
Correct |
108 ms |
165712 KB |
Output is correct |
36 |
Correct |
106 ms |
165692 KB |
Output is correct |
37 |
Correct |
104 ms |
165700 KB |
Output is correct |
38 |
Correct |
122 ms |
165948 KB |
Output is correct |
39 |
Correct |
189 ms |
165408 KB |
Output is correct |
40 |
Correct |
138 ms |
146768 KB |
Output is correct |
41 |
Correct |
139 ms |
165132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
86620 KB |
Output is correct |
2 |
Correct |
8 ms |
82520 KB |
Output is correct |
3 |
Correct |
11 ms |
96860 KB |
Output is correct |
4 |
Correct |
10 ms |
92764 KB |
Output is correct |
5 |
Correct |
10 ms |
96860 KB |
Output is correct |
6 |
Correct |
12 ms |
98960 KB |
Output is correct |
7 |
Correct |
11 ms |
98908 KB |
Output is correct |
8 |
Correct |
11 ms |
98908 KB |
Output is correct |
9 |
Correct |
11 ms |
98904 KB |
Output is correct |
10 |
Correct |
11 ms |
98908 KB |
Output is correct |
11 |
Correct |
13 ms |
103004 KB |
Output is correct |
12 |
Correct |
14 ms |
107104 KB |
Output is correct |
13 |
Correct |
15 ms |
107100 KB |
Output is correct |
14 |
Correct |
14 ms |
107100 KB |
Output is correct |
15 |
Correct |
14 ms |
107100 KB |
Output is correct |
16 |
Correct |
14 ms |
107064 KB |
Output is correct |
17 |
Correct |
13 ms |
107100 KB |
Output is correct |
18 |
Correct |
14 ms |
107100 KB |
Output is correct |
19 |
Correct |
870 ms |
237168 KB |
Output is correct |
20 |
Correct |
863 ms |
237244 KB |
Output is correct |
21 |
Correct |
849 ms |
237136 KB |
Output is correct |
22 |
Correct |
852 ms |
237256 KB |
Output is correct |
23 |
Correct |
2501 ms |
239380 KB |
Output is correct |
24 |
Correct |
60 ms |
140260 KB |
Output is correct |
25 |
Correct |
54 ms |
140224 KB |
Output is correct |
26 |
Correct |
72 ms |
138320 KB |
Output is correct |
27 |
Correct |
102 ms |
138436 KB |
Output is correct |
28 |
Correct |
90 ms |
138332 KB |
Output is correct |
29 |
Correct |
54 ms |
140368 KB |
Output is correct |
30 |
Correct |
55 ms |
140380 KB |
Output is correct |
31 |
Correct |
62 ms |
140120 KB |
Output is correct |
32 |
Correct |
35 ms |
100956 KB |
Output is correct |
33 |
Correct |
63 ms |
140372 KB |
Output is correct |
34 |
Correct |
156 ms |
164992 KB |
Output is correct |
35 |
Correct |
159 ms |
165168 KB |
Output is correct |
36 |
Correct |
102 ms |
164944 KB |
Output is correct |
37 |
Correct |
106 ms |
164944 KB |
Output is correct |
38 |
Correct |
105 ms |
165040 KB |
Output is correct |
39 |
Correct |
126 ms |
163668 KB |
Output is correct |
40 |
Correct |
132 ms |
163592 KB |
Output is correct |
41 |
Correct |
168 ms |
163740 KB |
Output is correct |
42 |
Correct |
155 ms |
163600 KB |
Output is correct |
43 |
Correct |
183 ms |
163688 KB |
Output is correct |
44 |
Correct |
243 ms |
163664 KB |
Output is correct |
45 |
Correct |
233 ms |
163664 KB |
Output is correct |
46 |
Correct |
243 ms |
163600 KB |
Output is correct |
47 |
Correct |
289 ms |
163684 KB |
Output is correct |
48 |
Correct |
236 ms |
163664 KB |
Output is correct |
49 |
Correct |
108 ms |
165728 KB |
Output is correct |
50 |
Correct |
108 ms |
165712 KB |
Output is correct |
51 |
Correct |
106 ms |
165692 KB |
Output is correct |
52 |
Correct |
104 ms |
165700 KB |
Output is correct |
53 |
Correct |
122 ms |
165948 KB |
Output is correct |
54 |
Correct |
189 ms |
165408 KB |
Output is correct |
55 |
Correct |
138 ms |
146768 KB |
Output is correct |
56 |
Correct |
139 ms |
165132 KB |
Output is correct |
57 |
Correct |
848 ms |
254292 KB |
Output is correct |
58 |
Correct |
894 ms |
258464 KB |
Output is correct |
59 |
Correct |
779 ms |
258360 KB |
Output is correct |
60 |
Correct |
805 ms |
245932 KB |
Output is correct |
61 |
Correct |
831 ms |
262144 KB |
Output is correct |
62 |
Correct |
786 ms |
262144 KB |
Output is correct |
63 |
Correct |
611 ms |
262144 KB |
Output is correct |
64 |
Correct |
634 ms |
262144 KB |
Output is correct |
65 |
Correct |
2100 ms |
262144 KB |
Output is correct |
66 |
Correct |
2120 ms |
262144 KB |
Output is correct |
67 |
Correct |
2258 ms |
262144 KB |
Output is correct |
68 |
Correct |
2469 ms |
262144 KB |
Output is correct |
69 |
Correct |
2442 ms |
262144 KB |
Output is correct |
70 |
Correct |
2478 ms |
262144 KB |
Output is correct |
71 |
Correct |
2478 ms |
262144 KB |
Output is correct |
72 |
Correct |
2523 ms |
262144 KB |
Output is correct |
73 |
Correct |
541 ms |
262144 KB |
Output is correct |
74 |
Correct |
565 ms |
262144 KB |
Output is correct |
75 |
Correct |
529 ms |
262144 KB |
Output is correct |
76 |
Correct |
503 ms |
262144 KB |
Output is correct |
77 |
Correct |
504 ms |
262144 KB |
Output is correct |
78 |
Correct |
1861 ms |
262144 KB |
Output is correct |
79 |
Correct |
1205 ms |
256456 KB |
Output is correct |
80 |
Correct |
1043 ms |
262144 KB |
Output is correct |