#include <bits/stdc++.h>
using namespace std;
int n, m, a [1000006];
struct query{
int l, k, idx;
};
vector <query> v [1000006];
bool ans [1000006];
int bst [1000006];
void upd (int x, int val){
while (x <= n){
bst [x] = max (bst [x], val);
x += x & -x;
}
}
int q (int x){
int ans = 0;
while (x > 0){
ans = max (ans, bst [x]);
x -= x & -x;
}
return ans;
}
int main (){
ios::sync_with_stdio (false);
cin.tie (0);
cin >> n >> m;
for (int i = 0; i < n; i ++) cin >> a [i];
for (int i = 0; i < m; i ++){
int l, r, k;
cin >> l >> r >> k;
v [r - 1].push_back ({l - 1, k, i});
}
stack <pair <int, int> > s;
for (int i = 0; i < n; i ++){
while (!s.empty () && s.top ().first <= a [i]) s.pop ();
if (!s.empty ()) upd (n - s.top ().second, s.top ().first + a [i]);
s.push ({a [i], i});
for (auto Q : v [i]){
if (q (n - Q.l) <= Q.k) ans [Q.idx] = 1;
else ans [Q.idx] = 0;
}
}
for (int i = 0; i < m; i ++) cout << ans [i] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
23800 KB |
Output is correct |
2 |
Correct |
26 ms |
23800 KB |
Output is correct |
3 |
Correct |
25 ms |
23928 KB |
Output is correct |
4 |
Correct |
25 ms |
24056 KB |
Output is correct |
5 |
Correct |
25 ms |
23800 KB |
Output is correct |
6 |
Correct |
25 ms |
23928 KB |
Output is correct |
7 |
Correct |
34 ms |
24056 KB |
Output is correct |
8 |
Correct |
27 ms |
23800 KB |
Output is correct |
9 |
Correct |
25 ms |
23800 KB |
Output is correct |
10 |
Correct |
25 ms |
23832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
23800 KB |
Output is correct |
2 |
Correct |
26 ms |
23800 KB |
Output is correct |
3 |
Correct |
25 ms |
23928 KB |
Output is correct |
4 |
Correct |
25 ms |
24056 KB |
Output is correct |
5 |
Correct |
25 ms |
23800 KB |
Output is correct |
6 |
Correct |
25 ms |
23928 KB |
Output is correct |
7 |
Correct |
34 ms |
24056 KB |
Output is correct |
8 |
Correct |
27 ms |
23800 KB |
Output is correct |
9 |
Correct |
25 ms |
23800 KB |
Output is correct |
10 |
Correct |
25 ms |
23832 KB |
Output is correct |
11 |
Correct |
32 ms |
23976 KB |
Output is correct |
12 |
Correct |
24 ms |
24008 KB |
Output is correct |
13 |
Correct |
27 ms |
24056 KB |
Output is correct |
14 |
Correct |
30 ms |
24184 KB |
Output is correct |
15 |
Correct |
32 ms |
24184 KB |
Output is correct |
16 |
Correct |
45 ms |
24184 KB |
Output is correct |
17 |
Correct |
32 ms |
24184 KB |
Output is correct |
18 |
Correct |
27 ms |
24056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1148 ms |
70764 KB |
Output is correct |
2 |
Correct |
1223 ms |
89328 KB |
Output is correct |
3 |
Correct |
1136 ms |
70648 KB |
Output is correct |
4 |
Correct |
1132 ms |
70876 KB |
Output is correct |
5 |
Correct |
1070 ms |
85372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
29176 KB |
Output is correct |
2 |
Correct |
95 ms |
28872 KB |
Output is correct |
3 |
Correct |
95 ms |
28536 KB |
Output is correct |
4 |
Correct |
95 ms |
28596 KB |
Output is correct |
5 |
Correct |
97 ms |
28668 KB |
Output is correct |
6 |
Correct |
78 ms |
28188 KB |
Output is correct |
7 |
Correct |
89 ms |
28124 KB |
Output is correct |
8 |
Correct |
98 ms |
28212 KB |
Output is correct |
9 |
Correct |
66 ms |
26924 KB |
Output is correct |
10 |
Correct |
89 ms |
28184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
23800 KB |
Output is correct |
2 |
Correct |
26 ms |
23800 KB |
Output is correct |
3 |
Correct |
25 ms |
23928 KB |
Output is correct |
4 |
Correct |
25 ms |
24056 KB |
Output is correct |
5 |
Correct |
25 ms |
23800 KB |
Output is correct |
6 |
Correct |
25 ms |
23928 KB |
Output is correct |
7 |
Correct |
34 ms |
24056 KB |
Output is correct |
8 |
Correct |
27 ms |
23800 KB |
Output is correct |
9 |
Correct |
25 ms |
23800 KB |
Output is correct |
10 |
Correct |
25 ms |
23832 KB |
Output is correct |
11 |
Correct |
32 ms |
23976 KB |
Output is correct |
12 |
Correct |
24 ms |
24008 KB |
Output is correct |
13 |
Correct |
27 ms |
24056 KB |
Output is correct |
14 |
Correct |
30 ms |
24184 KB |
Output is correct |
15 |
Correct |
32 ms |
24184 KB |
Output is correct |
16 |
Correct |
45 ms |
24184 KB |
Output is correct |
17 |
Correct |
32 ms |
24184 KB |
Output is correct |
18 |
Correct |
27 ms |
24056 KB |
Output is correct |
19 |
Correct |
226 ms |
36828 KB |
Output is correct |
20 |
Correct |
223 ms |
36856 KB |
Output is correct |
21 |
Correct |
191 ms |
36420 KB |
Output is correct |
22 |
Correct |
183 ms |
36396 KB |
Output is correct |
23 |
Correct |
187 ms |
36216 KB |
Output is correct |
24 |
Correct |
178 ms |
35388 KB |
Output is correct |
25 |
Correct |
183 ms |
35192 KB |
Output is correct |
26 |
Correct |
191 ms |
35676 KB |
Output is correct |
27 |
Correct |
196 ms |
35920 KB |
Output is correct |
28 |
Correct |
202 ms |
35676 KB |
Output is correct |
29 |
Correct |
210 ms |
36216 KB |
Output is correct |
30 |
Correct |
242 ms |
36064 KB |
Output is correct |
31 |
Correct |
234 ms |
36088 KB |
Output is correct |
32 |
Correct |
249 ms |
36112 KB |
Output is correct |
33 |
Correct |
239 ms |
36088 KB |
Output is correct |
34 |
Correct |
170 ms |
34860 KB |
Output is correct |
35 |
Correct |
188 ms |
34680 KB |
Output is correct |
36 |
Correct |
165 ms |
34556 KB |
Output is correct |
37 |
Correct |
158 ms |
34556 KB |
Output is correct |
38 |
Correct |
155 ms |
34808 KB |
Output is correct |
39 |
Correct |
192 ms |
34608 KB |
Output is correct |
40 |
Correct |
161 ms |
33096 KB |
Output is correct |
41 |
Correct |
187 ms |
33996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
23800 KB |
Output is correct |
2 |
Correct |
26 ms |
23800 KB |
Output is correct |
3 |
Correct |
25 ms |
23928 KB |
Output is correct |
4 |
Correct |
25 ms |
24056 KB |
Output is correct |
5 |
Correct |
25 ms |
23800 KB |
Output is correct |
6 |
Correct |
25 ms |
23928 KB |
Output is correct |
7 |
Correct |
34 ms |
24056 KB |
Output is correct |
8 |
Correct |
27 ms |
23800 KB |
Output is correct |
9 |
Correct |
25 ms |
23800 KB |
Output is correct |
10 |
Correct |
25 ms |
23832 KB |
Output is correct |
11 |
Correct |
32 ms |
23976 KB |
Output is correct |
12 |
Correct |
24 ms |
24008 KB |
Output is correct |
13 |
Correct |
27 ms |
24056 KB |
Output is correct |
14 |
Correct |
30 ms |
24184 KB |
Output is correct |
15 |
Correct |
32 ms |
24184 KB |
Output is correct |
16 |
Correct |
45 ms |
24184 KB |
Output is correct |
17 |
Correct |
32 ms |
24184 KB |
Output is correct |
18 |
Correct |
27 ms |
24056 KB |
Output is correct |
19 |
Correct |
1148 ms |
70764 KB |
Output is correct |
20 |
Correct |
1223 ms |
89328 KB |
Output is correct |
21 |
Correct |
1136 ms |
70648 KB |
Output is correct |
22 |
Correct |
1132 ms |
70876 KB |
Output is correct |
23 |
Correct |
1070 ms |
85372 KB |
Output is correct |
24 |
Correct |
103 ms |
29176 KB |
Output is correct |
25 |
Correct |
95 ms |
28872 KB |
Output is correct |
26 |
Correct |
95 ms |
28536 KB |
Output is correct |
27 |
Correct |
95 ms |
28596 KB |
Output is correct |
28 |
Correct |
97 ms |
28668 KB |
Output is correct |
29 |
Correct |
78 ms |
28188 KB |
Output is correct |
30 |
Correct |
89 ms |
28124 KB |
Output is correct |
31 |
Correct |
98 ms |
28212 KB |
Output is correct |
32 |
Correct |
66 ms |
26924 KB |
Output is correct |
33 |
Correct |
89 ms |
28184 KB |
Output is correct |
34 |
Correct |
226 ms |
36828 KB |
Output is correct |
35 |
Correct |
223 ms |
36856 KB |
Output is correct |
36 |
Correct |
191 ms |
36420 KB |
Output is correct |
37 |
Correct |
183 ms |
36396 KB |
Output is correct |
38 |
Correct |
187 ms |
36216 KB |
Output is correct |
39 |
Correct |
178 ms |
35388 KB |
Output is correct |
40 |
Correct |
183 ms |
35192 KB |
Output is correct |
41 |
Correct |
191 ms |
35676 KB |
Output is correct |
42 |
Correct |
196 ms |
35920 KB |
Output is correct |
43 |
Correct |
202 ms |
35676 KB |
Output is correct |
44 |
Correct |
210 ms |
36216 KB |
Output is correct |
45 |
Correct |
242 ms |
36064 KB |
Output is correct |
46 |
Correct |
234 ms |
36088 KB |
Output is correct |
47 |
Correct |
249 ms |
36112 KB |
Output is correct |
48 |
Correct |
239 ms |
36088 KB |
Output is correct |
49 |
Correct |
170 ms |
34860 KB |
Output is correct |
50 |
Correct |
188 ms |
34680 KB |
Output is correct |
51 |
Correct |
165 ms |
34556 KB |
Output is correct |
52 |
Correct |
158 ms |
34556 KB |
Output is correct |
53 |
Correct |
155 ms |
34808 KB |
Output is correct |
54 |
Correct |
192 ms |
34608 KB |
Output is correct |
55 |
Correct |
161 ms |
33096 KB |
Output is correct |
56 |
Correct |
187 ms |
33996 KB |
Output is correct |
57 |
Correct |
1154 ms |
89664 KB |
Output is correct |
58 |
Correct |
1156 ms |
89604 KB |
Output is correct |
59 |
Correct |
1087 ms |
87828 KB |
Output is correct |
60 |
Correct |
1088 ms |
87580 KB |
Output is correct |
61 |
Correct |
1096 ms |
87904 KB |
Output is correct |
62 |
Correct |
1107 ms |
88008 KB |
Output is correct |
63 |
Correct |
754 ms |
80264 KB |
Output is correct |
64 |
Correct |
764 ms |
80232 KB |
Output is correct |
65 |
Correct |
1014 ms |
83844 KB |
Output is correct |
66 |
Correct |
1047 ms |
83700 KB |
Output is correct |
67 |
Correct |
1034 ms |
83648 KB |
Output is correct |
68 |
Correct |
1065 ms |
85128 KB |
Output is correct |
69 |
Correct |
1092 ms |
84832 KB |
Output is correct |
70 |
Correct |
1067 ms |
85312 KB |
Output is correct |
71 |
Correct |
1043 ms |
84808 KB |
Output is correct |
72 |
Correct |
1060 ms |
85308 KB |
Output is correct |
73 |
Correct |
663 ms |
76408 KB |
Output is correct |
74 |
Correct |
714 ms |
77484 KB |
Output is correct |
75 |
Correct |
683 ms |
76508 KB |
Output is correct |
76 |
Correct |
698 ms |
76516 KB |
Output is correct |
77 |
Correct |
727 ms |
76172 KB |
Output is correct |
78 |
Correct |
954 ms |
79108 KB |
Output is correct |
79 |
Correct |
752 ms |
68676 KB |
Output is correct |
80 |
Correct |
895 ms |
74868 KB |
Output is correct |