#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef pair<int,int> ii;
typedef tuple<int,int,int, int> iiii;
int n,m;
ii p[1000005];
int ans[1000005];
int w[1000005];
vector<ii> st;
iiii q[1000005];
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 up(int x, int nv){
if (s == e) {
v = max(v,nv);
return;
}
if (x > m) r->up(x,nv);
else if (x <= m) l->up(x,nv);
v = max(l->v,r->v);
}
int qu(int qs ,int qe){
if (qs == s && qe == e) return v;
if (qs > m) return r->qu(qs,qe);
else if (qe <= m) return l->qu(qs,qe);
else return max(l->qu(qs,m),r->qu(m+1,qe));
}
} *root;
int main(){
scanf("%d%d",&n,&m);
for (int i = 1; i <= n; i++) {
scanf("%d",&w[i]);
while (st.size() && st.back().fi <= w[i]) st.pop_back();
if (st.size()) p[i] = {st.back().fi + w[i], st.back().se};
else p[i] = {0,1};
st.push_back({w[i],i});
}
root = new node(1,n);
int l,r,k;
for (int i = 0; i < m; i++){
scanf("%d%d%d",&l,&r,&k);
q[i] = {r,l,k,i};
}
int cur = 0;
sort(q,q+m);
for (int i = 0; i < m; i++){
int l,r,k,id;
tie(r,l,k,id) = q[i];
while (cur <= r){
root->up(p[cur].se, p[cur].fi);
cur++;
}
ans[id] = (root->qu(l,r) <= k);
}
for (int i = 0; i < m; i++){
printf("%d\n",ans[i]);
}
}
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
41 | scanf("%d%d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~
sortbooks.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
43 | scanf("%d",&w[i]);
| ~~~~~^~~~~~~~~~~~
sortbooks.cpp:52:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
52 | scanf("%d%d%d",&l,&r,&k);
| ~~~~~^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
640 KB |
Output is correct |
12 |
Correct |
7 ms |
1024 KB |
Output is correct |
13 |
Correct |
5 ms |
1024 KB |
Output is correct |
14 |
Correct |
7 ms |
1152 KB |
Output is correct |
15 |
Correct |
7 ms |
1152 KB |
Output is correct |
16 |
Correct |
6 ms |
1152 KB |
Output is correct |
17 |
Correct |
5 ms |
1024 KB |
Output is correct |
18 |
Correct |
5 ms |
1024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2036 ms |
127616 KB |
Output is correct |
2 |
Correct |
2077 ms |
160592 KB |
Output is correct |
3 |
Correct |
2158 ms |
160448 KB |
Output is correct |
4 |
Correct |
2000 ms |
160552 KB |
Output is correct |
5 |
Correct |
1946 ms |
160632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
140 ms |
13432 KB |
Output is correct |
2 |
Correct |
129 ms |
14968 KB |
Output is correct |
3 |
Correct |
151 ms |
15096 KB |
Output is correct |
4 |
Correct |
129 ms |
15044 KB |
Output is correct |
5 |
Correct |
132 ms |
15096 KB |
Output is correct |
6 |
Correct |
107 ms |
14844 KB |
Output is correct |
7 |
Correct |
110 ms |
14972 KB |
Output is correct |
8 |
Correct |
114 ms |
14712 KB |
Output is correct |
9 |
Correct |
58 ms |
3832 KB |
Output is correct |
10 |
Correct |
114 ms |
14712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
640 KB |
Output is correct |
12 |
Correct |
7 ms |
1024 KB |
Output is correct |
13 |
Correct |
5 ms |
1024 KB |
Output is correct |
14 |
Correct |
7 ms |
1152 KB |
Output is correct |
15 |
Correct |
7 ms |
1152 KB |
Output is correct |
16 |
Correct |
6 ms |
1152 KB |
Output is correct |
17 |
Correct |
5 ms |
1024 KB |
Output is correct |
18 |
Correct |
5 ms |
1024 KB |
Output is correct |
19 |
Correct |
333 ms |
32376 KB |
Output is correct |
20 |
Correct |
331 ms |
32376 KB |
Output is correct |
21 |
Correct |
280 ms |
32248 KB |
Output is correct |
22 |
Correct |
284 ms |
32248 KB |
Output is correct |
23 |
Correct |
285 ms |
32248 KB |
Output is correct |
24 |
Correct |
262 ms |
32080 KB |
Output is correct |
25 |
Correct |
270 ms |
32120 KB |
Output is correct |
26 |
Correct |
305 ms |
32508 KB |
Output is correct |
27 |
Correct |
298 ms |
32376 KB |
Output is correct |
28 |
Correct |
304 ms |
32376 KB |
Output is correct |
29 |
Correct |
320 ms |
32368 KB |
Output is correct |
30 |
Correct |
325 ms |
32396 KB |
Output is correct |
31 |
Correct |
322 ms |
32480 KB |
Output is correct |
32 |
Correct |
316 ms |
32548 KB |
Output is correct |
33 |
Correct |
320 ms |
32504 KB |
Output is correct |
34 |
Correct |
244 ms |
31992 KB |
Output is correct |
35 |
Correct |
255 ms |
31992 KB |
Output is correct |
36 |
Correct |
243 ms |
31864 KB |
Output is correct |
37 |
Correct |
239 ms |
31864 KB |
Output is correct |
38 |
Correct |
246 ms |
31992 KB |
Output is correct |
39 |
Correct |
280 ms |
30968 KB |
Output is correct |
40 |
Correct |
211 ms |
23032 KB |
Output is correct |
41 |
Correct |
265 ms |
30584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
640 KB |
Output is correct |
12 |
Correct |
7 ms |
1024 KB |
Output is correct |
13 |
Correct |
5 ms |
1024 KB |
Output is correct |
14 |
Correct |
7 ms |
1152 KB |
Output is correct |
15 |
Correct |
7 ms |
1152 KB |
Output is correct |
16 |
Correct |
6 ms |
1152 KB |
Output is correct |
17 |
Correct |
5 ms |
1024 KB |
Output is correct |
18 |
Correct |
5 ms |
1024 KB |
Output is correct |
19 |
Correct |
2036 ms |
127616 KB |
Output is correct |
20 |
Correct |
2077 ms |
160592 KB |
Output is correct |
21 |
Correct |
2158 ms |
160448 KB |
Output is correct |
22 |
Correct |
2000 ms |
160552 KB |
Output is correct |
23 |
Correct |
1946 ms |
160632 KB |
Output is correct |
24 |
Correct |
140 ms |
13432 KB |
Output is correct |
25 |
Correct |
129 ms |
14968 KB |
Output is correct |
26 |
Correct |
151 ms |
15096 KB |
Output is correct |
27 |
Correct |
129 ms |
15044 KB |
Output is correct |
28 |
Correct |
132 ms |
15096 KB |
Output is correct |
29 |
Correct |
107 ms |
14844 KB |
Output is correct |
30 |
Correct |
110 ms |
14972 KB |
Output is correct |
31 |
Correct |
114 ms |
14712 KB |
Output is correct |
32 |
Correct |
58 ms |
3832 KB |
Output is correct |
33 |
Correct |
114 ms |
14712 KB |
Output is correct |
34 |
Correct |
333 ms |
32376 KB |
Output is correct |
35 |
Correct |
331 ms |
32376 KB |
Output is correct |
36 |
Correct |
280 ms |
32248 KB |
Output is correct |
37 |
Correct |
284 ms |
32248 KB |
Output is correct |
38 |
Correct |
285 ms |
32248 KB |
Output is correct |
39 |
Correct |
262 ms |
32080 KB |
Output is correct |
40 |
Correct |
270 ms |
32120 KB |
Output is correct |
41 |
Correct |
305 ms |
32508 KB |
Output is correct |
42 |
Correct |
298 ms |
32376 KB |
Output is correct |
43 |
Correct |
304 ms |
32376 KB |
Output is correct |
44 |
Correct |
320 ms |
32368 KB |
Output is correct |
45 |
Correct |
325 ms |
32396 KB |
Output is correct |
46 |
Correct |
322 ms |
32480 KB |
Output is correct |
47 |
Correct |
316 ms |
32548 KB |
Output is correct |
48 |
Correct |
320 ms |
32504 KB |
Output is correct |
49 |
Correct |
244 ms |
31992 KB |
Output is correct |
50 |
Correct |
255 ms |
31992 KB |
Output is correct |
51 |
Correct |
243 ms |
31864 KB |
Output is correct |
52 |
Correct |
239 ms |
31864 KB |
Output is correct |
53 |
Correct |
246 ms |
31992 KB |
Output is correct |
54 |
Correct |
280 ms |
30968 KB |
Output is correct |
55 |
Correct |
211 ms |
23032 KB |
Output is correct |
56 |
Correct |
265 ms |
30584 KB |
Output is correct |
57 |
Correct |
1942 ms |
161272 KB |
Output is correct |
58 |
Correct |
1983 ms |
161400 KB |
Output is correct |
59 |
Correct |
1935 ms |
161400 KB |
Output is correct |
60 |
Correct |
1883 ms |
161212 KB |
Output is correct |
61 |
Correct |
1913 ms |
161132 KB |
Output is correct |
62 |
Correct |
1964 ms |
161092 KB |
Output is correct |
63 |
Correct |
1409 ms |
159224 KB |
Output is correct |
64 |
Correct |
1476 ms |
159252 KB |
Output is correct |
65 |
Correct |
1926 ms |
161028 KB |
Output is correct |
66 |
Correct |
1882 ms |
161192 KB |
Output is correct |
67 |
Correct |
1820 ms |
161144 KB |
Output is correct |
68 |
Correct |
1877 ms |
161344 KB |
Output is correct |
69 |
Correct |
1904 ms |
161396 KB |
Output is correct |
70 |
Correct |
1891 ms |
161392 KB |
Output is correct |
71 |
Correct |
1904 ms |
161400 KB |
Output is correct |
72 |
Correct |
1928 ms |
161252 KB |
Output is correct |
73 |
Correct |
1311 ms |
158052 KB |
Output is correct |
74 |
Correct |
1324 ms |
158888 KB |
Output is correct |
75 |
Correct |
1315 ms |
157936 KB |
Output is correct |
76 |
Correct |
1302 ms |
157788 KB |
Output is correct |
77 |
Correct |
1328 ms |
157944 KB |
Output is correct |
78 |
Correct |
1680 ms |
155108 KB |
Output is correct |
79 |
Correct |
1161 ms |
99960 KB |
Output is correct |
80 |
Correct |
1586 ms |
152244 KB |
Output is correct |