#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 998244353
#define INF 1000000000000000000
#define EPS 1e-10
struct node {
int s, e, m, v;
node *l, *r;
node(int _s, int _e) {
s = _s, e = _e, m = (s+e)/2, v = 0;
if(s != e) {
l = new node(s, m);
r = new node(m+1, e);
}
}
void update(int x, int val) {
if(s == e) {v = val; return;}
else if(x > m) r->update(x, val);
else l->update(x, val);
v = max(l->v, r->v);
}
int rmax(int x, int y) {
if(x <= s && e <= y) return v;
else if(x > m) return r->rmax(x, y);
else if(y <= m) return l->rmax(x, y);
else return max(l->rmax(x, y), r->rmax(x, y));
}
} *root;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m, l, r, k, idx;
cin >> n >> m;
root = new node(0, n-1);
int a, ans[m];
pair<int, int> p[n];
tuple<int, int, int, int> qry[m];
stack<pair<int, int>> s;
for(int i = 0; i < n; i++) {
cin >> a;
while(s.size() && s.top().first <= a) s.pop();
if(s.size()) p[i] = {s.top().second, s.top().first+a};
else p[i] = {i, 0};
s.push({a, i});
}
for(int i = 0; i < m; i++) {
cin >> l >> r >> k;
l--; r--;
qry[i] = {r, l, k, i};
}
sort(qry, qry+m);
int cur = 0;
for(int i = 0; i < m; i++) {
tie(r, l, k, idx) = qry[i];
while(cur <= r) {
root->update(p[cur].first, p[cur].second);
cur++;
}
ans[idx] = root->rmax(l, r) <= k;
}
for(int i = 0; i < m; i++) cout << ans[i] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
232 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
232 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
12 |
Correct |
3 ms |
1108 KB |
Output is correct |
13 |
Correct |
4 ms |
1236 KB |
Output is correct |
14 |
Correct |
5 ms |
1364 KB |
Output is correct |
15 |
Correct |
5 ms |
1364 KB |
Output is correct |
16 |
Correct |
4 ms |
1236 KB |
Output is correct |
17 |
Correct |
3 ms |
1188 KB |
Output is correct |
18 |
Correct |
4 ms |
1236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1355 ms |
214292 KB |
Output is correct |
2 |
Correct |
1380 ms |
215088 KB |
Output is correct |
3 |
Correct |
1383 ms |
215056 KB |
Output is correct |
4 |
Correct |
1369 ms |
215060 KB |
Output is correct |
5 |
Correct |
1334 ms |
215164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
93 ms |
20420 KB |
Output is correct |
2 |
Correct |
86 ms |
20348 KB |
Output is correct |
3 |
Correct |
89 ms |
20428 KB |
Output is correct |
4 |
Correct |
93 ms |
20424 KB |
Output is correct |
5 |
Correct |
92 ms |
20484 KB |
Output is correct |
6 |
Correct |
74 ms |
20332 KB |
Output is correct |
7 |
Correct |
77 ms |
20220 KB |
Output is correct |
8 |
Correct |
77 ms |
20208 KB |
Output is correct |
9 |
Correct |
38 ms |
5824 KB |
Output is correct |
10 |
Correct |
82 ms |
20088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
232 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
12 |
Correct |
3 ms |
1108 KB |
Output is correct |
13 |
Correct |
4 ms |
1236 KB |
Output is correct |
14 |
Correct |
5 ms |
1364 KB |
Output is correct |
15 |
Correct |
5 ms |
1364 KB |
Output is correct |
16 |
Correct |
4 ms |
1236 KB |
Output is correct |
17 |
Correct |
3 ms |
1188 KB |
Output is correct |
18 |
Correct |
4 ms |
1236 KB |
Output is correct |
19 |
Correct |
242 ms |
43200 KB |
Output is correct |
20 |
Correct |
224 ms |
43276 KB |
Output is correct |
21 |
Correct |
186 ms |
43144 KB |
Output is correct |
22 |
Correct |
186 ms |
43080 KB |
Output is correct |
23 |
Correct |
191 ms |
43148 KB |
Output is correct |
24 |
Correct |
182 ms |
42952 KB |
Output is correct |
25 |
Correct |
176 ms |
42948 KB |
Output is correct |
26 |
Correct |
194 ms |
43208 KB |
Output is correct |
27 |
Correct |
197 ms |
43340 KB |
Output is correct |
28 |
Correct |
204 ms |
43204 KB |
Output is correct |
29 |
Correct |
225 ms |
43336 KB |
Output is correct |
30 |
Correct |
226 ms |
43296 KB |
Output is correct |
31 |
Correct |
244 ms |
43208 KB |
Output is correct |
32 |
Correct |
225 ms |
43332 KB |
Output is correct |
33 |
Correct |
236 ms |
43200 KB |
Output is correct |
34 |
Correct |
172 ms |
42820 KB |
Output is correct |
35 |
Correct |
170 ms |
42908 KB |
Output is correct |
36 |
Correct |
162 ms |
42724 KB |
Output is correct |
37 |
Correct |
170 ms |
42720 KB |
Output is correct |
38 |
Correct |
184 ms |
42912 KB |
Output is correct |
39 |
Correct |
210 ms |
41860 KB |
Output is correct |
40 |
Correct |
156 ms |
31444 KB |
Output is correct |
41 |
Correct |
177 ms |
41424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
232 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
12 |
Correct |
3 ms |
1108 KB |
Output is correct |
13 |
Correct |
4 ms |
1236 KB |
Output is correct |
14 |
Correct |
5 ms |
1364 KB |
Output is correct |
15 |
Correct |
5 ms |
1364 KB |
Output is correct |
16 |
Correct |
4 ms |
1236 KB |
Output is correct |
17 |
Correct |
3 ms |
1188 KB |
Output is correct |
18 |
Correct |
4 ms |
1236 KB |
Output is correct |
19 |
Correct |
1355 ms |
214292 KB |
Output is correct |
20 |
Correct |
1380 ms |
215088 KB |
Output is correct |
21 |
Correct |
1383 ms |
215056 KB |
Output is correct |
22 |
Correct |
1369 ms |
215060 KB |
Output is correct |
23 |
Correct |
1334 ms |
215164 KB |
Output is correct |
24 |
Correct |
93 ms |
20420 KB |
Output is correct |
25 |
Correct |
86 ms |
20348 KB |
Output is correct |
26 |
Correct |
89 ms |
20428 KB |
Output is correct |
27 |
Correct |
93 ms |
20424 KB |
Output is correct |
28 |
Correct |
92 ms |
20484 KB |
Output is correct |
29 |
Correct |
74 ms |
20332 KB |
Output is correct |
30 |
Correct |
77 ms |
20220 KB |
Output is correct |
31 |
Correct |
77 ms |
20208 KB |
Output is correct |
32 |
Correct |
38 ms |
5824 KB |
Output is correct |
33 |
Correct |
82 ms |
20088 KB |
Output is correct |
34 |
Correct |
242 ms |
43200 KB |
Output is correct |
35 |
Correct |
224 ms |
43276 KB |
Output is correct |
36 |
Correct |
186 ms |
43144 KB |
Output is correct |
37 |
Correct |
186 ms |
43080 KB |
Output is correct |
38 |
Correct |
191 ms |
43148 KB |
Output is correct |
39 |
Correct |
182 ms |
42952 KB |
Output is correct |
40 |
Correct |
176 ms |
42948 KB |
Output is correct |
41 |
Correct |
194 ms |
43208 KB |
Output is correct |
42 |
Correct |
197 ms |
43340 KB |
Output is correct |
43 |
Correct |
204 ms |
43204 KB |
Output is correct |
44 |
Correct |
225 ms |
43336 KB |
Output is correct |
45 |
Correct |
226 ms |
43296 KB |
Output is correct |
46 |
Correct |
244 ms |
43208 KB |
Output is correct |
47 |
Correct |
225 ms |
43332 KB |
Output is correct |
48 |
Correct |
236 ms |
43200 KB |
Output is correct |
49 |
Correct |
172 ms |
42820 KB |
Output is correct |
50 |
Correct |
170 ms |
42908 KB |
Output is correct |
51 |
Correct |
162 ms |
42724 KB |
Output is correct |
52 |
Correct |
170 ms |
42720 KB |
Output is correct |
53 |
Correct |
184 ms |
42912 KB |
Output is correct |
54 |
Correct |
210 ms |
41860 KB |
Output is correct |
55 |
Correct |
156 ms |
31444 KB |
Output is correct |
56 |
Correct |
177 ms |
41424 KB |
Output is correct |
57 |
Correct |
1419 ms |
215476 KB |
Output is correct |
58 |
Correct |
1360 ms |
215888 KB |
Output is correct |
59 |
Correct |
1283 ms |
215736 KB |
Output is correct |
60 |
Correct |
1269 ms |
215732 KB |
Output is correct |
61 |
Correct |
1279 ms |
215784 KB |
Output is correct |
62 |
Correct |
1310 ms |
215932 KB |
Output is correct |
63 |
Correct |
955 ms |
213976 KB |
Output is correct |
64 |
Correct |
942 ms |
213928 KB |
Output is correct |
65 |
Correct |
1328 ms |
215224 KB |
Output is correct |
66 |
Correct |
1318 ms |
215212 KB |
Output is correct |
67 |
Correct |
1287 ms |
215124 KB |
Output is correct |
68 |
Correct |
1428 ms |
215544 KB |
Output is correct |
69 |
Correct |
1387 ms |
215444 KB |
Output is correct |
70 |
Correct |
1493 ms |
215292 KB |
Output is correct |
71 |
Correct |
1464 ms |
215180 KB |
Output is correct |
72 |
Correct |
1381 ms |
215272 KB |
Output is correct |
73 |
Correct |
928 ms |
212100 KB |
Output is correct |
74 |
Correct |
941 ms |
213232 KB |
Output is correct |
75 |
Correct |
908 ms |
212280 KB |
Output is correct |
76 |
Correct |
913 ms |
212444 KB |
Output is correct |
77 |
Correct |
885 ms |
212360 KB |
Output is correct |
78 |
Correct |
1209 ms |
209852 KB |
Output is correct |
79 |
Correct |
849 ms |
137972 KB |
Output is correct |
80 |
Correct |
1121 ms |
206768 KB |
Output is correct |