# include <bits/stdc++.h>
# define FILE
using namespace std;
const int N = 1e6 + 100;
int n, m, w[N], l[N], ls[N], rs[N], ks[N], ans[N], mx[4*N];
vector < int > ids[N];
void update( int pos, int val, int tl = 1, int tr = n, int td = 1 ){
if( tl == tr )
mx[td] = max( mx[td], val );
else{
int tm = ( tl+tr ) >> 1;
if( pos <= tm )
update( pos, val, tl, tm, td+td );
else
update( pos, val, tm+1, tr, td+td+1 );
mx[td] = max( mx[td+td], mx[td+td+1] );
}
}
int get( int l, int r, int tl = 1, int tr = n, int td = 1 ){
if( l > r || l > tr || tl > r || tl > tr )
return 0;
if( l <= tl && tr <= r )
return mx[td];
else{
int tm = ( tl + tr )>> 1;
return max( get( l, r, tl, tm, td+td ), get( l,r, tm+1, tr, td+td+1 )) ;
}
}
int main(){
# ifdef FILEs
freopen( "input.txt", "r", stdin );
freopen( "output.txt", "w", stdout );
# endif
scanf( "%d %d", &n, &m);
for( int i = 1; i <= n; i ++ ){
scanf( "%d", w+i );
l[i] = i-1;
while(l[i] && w[l[i]] <= w[i] ){
l[i] = l[l[i]];
}
}
for( int i = 1; i <= m; i ++ ){
scanf( "%d %d %d", ls+i, rs+i, ks+i );
ids[rs[i]].push_back( i );
}
for( int i = 1; i <= n; i ++ ){
if( l[i] )
update( l[i], w[i] + w[l[i]] );
for( auto id: ids[i] ){
ans[id] = (get( ls[id], rs[id] ) <= ks[id]);
}
}
for( int i = 1; i <= m; i++ ){
printf("%d\n", ans[i]);
}
}
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf( "%d %d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~~~
sortbooks.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf( "%d", w+i );
~~~~~^~~~~~~~~~~~~
sortbooks.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf( "%d %d %d", ls+i, rs+i, ks+i );
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
23928 KB |
Output is correct |
2 |
Correct |
22 ms |
23800 KB |
Output is correct |
3 |
Correct |
22 ms |
23800 KB |
Output is correct |
4 |
Correct |
23 ms |
23800 KB |
Output is correct |
5 |
Correct |
22 ms |
23800 KB |
Output is correct |
6 |
Correct |
23 ms |
23928 KB |
Output is correct |
7 |
Correct |
24 ms |
23928 KB |
Output is correct |
8 |
Correct |
24 ms |
23928 KB |
Output is correct |
9 |
Correct |
23 ms |
23928 KB |
Output is correct |
10 |
Correct |
28 ms |
23928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
23928 KB |
Output is correct |
2 |
Correct |
22 ms |
23800 KB |
Output is correct |
3 |
Correct |
22 ms |
23800 KB |
Output is correct |
4 |
Correct |
23 ms |
23800 KB |
Output is correct |
5 |
Correct |
22 ms |
23800 KB |
Output is correct |
6 |
Correct |
23 ms |
23928 KB |
Output is correct |
7 |
Correct |
24 ms |
23928 KB |
Output is correct |
8 |
Correct |
24 ms |
23928 KB |
Output is correct |
9 |
Correct |
23 ms |
23928 KB |
Output is correct |
10 |
Correct |
28 ms |
23928 KB |
Output is correct |
11 |
Correct |
27 ms |
24092 KB |
Output is correct |
12 |
Correct |
32 ms |
24172 KB |
Output is correct |
13 |
Correct |
28 ms |
24184 KB |
Output is correct |
14 |
Correct |
29 ms |
24312 KB |
Output is correct |
15 |
Correct |
29 ms |
24312 KB |
Output is correct |
16 |
Correct |
27 ms |
24184 KB |
Output is correct |
17 |
Correct |
27 ms |
24184 KB |
Output is correct |
18 |
Correct |
27 ms |
24184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2199 ms |
75852 KB |
Output is correct |
2 |
Correct |
2135 ms |
76084 KB |
Output is correct |
3 |
Correct |
2089 ms |
76252 KB |
Output is correct |
4 |
Correct |
2072 ms |
75992 KB |
Output is correct |
5 |
Correct |
1681 ms |
67676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
155 ms |
29244 KB |
Output is correct |
2 |
Correct |
140 ms |
28536 KB |
Output is correct |
3 |
Correct |
131 ms |
27992 KB |
Output is correct |
4 |
Correct |
143 ms |
29916 KB |
Output is correct |
5 |
Correct |
136 ms |
30072 KB |
Output is correct |
6 |
Correct |
114 ms |
28836 KB |
Output is correct |
7 |
Correct |
108 ms |
28920 KB |
Output is correct |
8 |
Correct |
124 ms |
29684 KB |
Output is correct |
9 |
Correct |
75 ms |
27508 KB |
Output is correct |
10 |
Correct |
124 ms |
29684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
23928 KB |
Output is correct |
2 |
Correct |
22 ms |
23800 KB |
Output is correct |
3 |
Correct |
22 ms |
23800 KB |
Output is correct |
4 |
Correct |
23 ms |
23800 KB |
Output is correct |
5 |
Correct |
22 ms |
23800 KB |
Output is correct |
6 |
Correct |
23 ms |
23928 KB |
Output is correct |
7 |
Correct |
24 ms |
23928 KB |
Output is correct |
8 |
Correct |
24 ms |
23928 KB |
Output is correct |
9 |
Correct |
23 ms |
23928 KB |
Output is correct |
10 |
Correct |
28 ms |
23928 KB |
Output is correct |
11 |
Correct |
27 ms |
24092 KB |
Output is correct |
12 |
Correct |
32 ms |
24172 KB |
Output is correct |
13 |
Correct |
28 ms |
24184 KB |
Output is correct |
14 |
Correct |
29 ms |
24312 KB |
Output is correct |
15 |
Correct |
29 ms |
24312 KB |
Output is correct |
16 |
Correct |
27 ms |
24184 KB |
Output is correct |
17 |
Correct |
27 ms |
24184 KB |
Output is correct |
18 |
Correct |
27 ms |
24184 KB |
Output is correct |
19 |
Correct |
348 ms |
34424 KB |
Output is correct |
20 |
Correct |
360 ms |
34656 KB |
Output is correct |
21 |
Correct |
297 ms |
32728 KB |
Output is correct |
22 |
Correct |
290 ms |
32760 KB |
Output is correct |
23 |
Correct |
300 ms |
32944 KB |
Output is correct |
24 |
Correct |
244 ms |
30584 KB |
Output is correct |
25 |
Correct |
248 ms |
36728 KB |
Output is correct |
26 |
Correct |
266 ms |
37624 KB |
Output is correct |
27 |
Correct |
268 ms |
37624 KB |
Output is correct |
28 |
Correct |
286 ms |
38008 KB |
Output is correct |
29 |
Correct |
364 ms |
38984 KB |
Output is correct |
30 |
Correct |
342 ms |
38908 KB |
Output is correct |
31 |
Correct |
326 ms |
38776 KB |
Output is correct |
32 |
Correct |
305 ms |
38656 KB |
Output is correct |
33 |
Correct |
304 ms |
38832 KB |
Output is correct |
34 |
Correct |
228 ms |
36344 KB |
Output is correct |
35 |
Correct |
233 ms |
36472 KB |
Output is correct |
36 |
Correct |
220 ms |
36216 KB |
Output is correct |
37 |
Correct |
223 ms |
36088 KB |
Output is correct |
38 |
Correct |
241 ms |
36344 KB |
Output is correct |
39 |
Correct |
267 ms |
37876 KB |
Output is correct |
40 |
Correct |
209 ms |
35568 KB |
Output is correct |
41 |
Correct |
257 ms |
36848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
23928 KB |
Output is correct |
2 |
Correct |
22 ms |
23800 KB |
Output is correct |
3 |
Correct |
22 ms |
23800 KB |
Output is correct |
4 |
Correct |
23 ms |
23800 KB |
Output is correct |
5 |
Correct |
22 ms |
23800 KB |
Output is correct |
6 |
Correct |
23 ms |
23928 KB |
Output is correct |
7 |
Correct |
24 ms |
23928 KB |
Output is correct |
8 |
Correct |
24 ms |
23928 KB |
Output is correct |
9 |
Correct |
23 ms |
23928 KB |
Output is correct |
10 |
Correct |
28 ms |
23928 KB |
Output is correct |
11 |
Correct |
27 ms |
24092 KB |
Output is correct |
12 |
Correct |
32 ms |
24172 KB |
Output is correct |
13 |
Correct |
28 ms |
24184 KB |
Output is correct |
14 |
Correct |
29 ms |
24312 KB |
Output is correct |
15 |
Correct |
29 ms |
24312 KB |
Output is correct |
16 |
Correct |
27 ms |
24184 KB |
Output is correct |
17 |
Correct |
27 ms |
24184 KB |
Output is correct |
18 |
Correct |
27 ms |
24184 KB |
Output is correct |
19 |
Correct |
2199 ms |
75852 KB |
Output is correct |
20 |
Correct |
2135 ms |
76084 KB |
Output is correct |
21 |
Correct |
2089 ms |
76252 KB |
Output is correct |
22 |
Correct |
2072 ms |
75992 KB |
Output is correct |
23 |
Correct |
1681 ms |
67676 KB |
Output is correct |
24 |
Correct |
155 ms |
29244 KB |
Output is correct |
25 |
Correct |
140 ms |
28536 KB |
Output is correct |
26 |
Correct |
131 ms |
27992 KB |
Output is correct |
27 |
Correct |
143 ms |
29916 KB |
Output is correct |
28 |
Correct |
136 ms |
30072 KB |
Output is correct |
29 |
Correct |
114 ms |
28836 KB |
Output is correct |
30 |
Correct |
108 ms |
28920 KB |
Output is correct |
31 |
Correct |
124 ms |
29684 KB |
Output is correct |
32 |
Correct |
75 ms |
27508 KB |
Output is correct |
33 |
Correct |
124 ms |
29684 KB |
Output is correct |
34 |
Correct |
348 ms |
34424 KB |
Output is correct |
35 |
Correct |
360 ms |
34656 KB |
Output is correct |
36 |
Correct |
297 ms |
32728 KB |
Output is correct |
37 |
Correct |
290 ms |
32760 KB |
Output is correct |
38 |
Correct |
300 ms |
32944 KB |
Output is correct |
39 |
Correct |
244 ms |
30584 KB |
Output is correct |
40 |
Correct |
248 ms |
36728 KB |
Output is correct |
41 |
Correct |
266 ms |
37624 KB |
Output is correct |
42 |
Correct |
268 ms |
37624 KB |
Output is correct |
43 |
Correct |
286 ms |
38008 KB |
Output is correct |
44 |
Correct |
364 ms |
38984 KB |
Output is correct |
45 |
Correct |
342 ms |
38908 KB |
Output is correct |
46 |
Correct |
326 ms |
38776 KB |
Output is correct |
47 |
Correct |
305 ms |
38656 KB |
Output is correct |
48 |
Correct |
304 ms |
38832 KB |
Output is correct |
49 |
Correct |
228 ms |
36344 KB |
Output is correct |
50 |
Correct |
233 ms |
36472 KB |
Output is correct |
51 |
Correct |
220 ms |
36216 KB |
Output is correct |
52 |
Correct |
223 ms |
36088 KB |
Output is correct |
53 |
Correct |
241 ms |
36344 KB |
Output is correct |
54 |
Correct |
267 ms |
37876 KB |
Output is correct |
55 |
Correct |
209 ms |
35568 KB |
Output is correct |
56 |
Correct |
257 ms |
36848 KB |
Output is correct |
57 |
Correct |
2080 ms |
87860 KB |
Output is correct |
58 |
Correct |
2070 ms |
87756 KB |
Output is correct |
59 |
Correct |
1969 ms |
83456 KB |
Output is correct |
60 |
Correct |
2071 ms |
93328 KB |
Output is correct |
61 |
Correct |
1982 ms |
83576 KB |
Output is correct |
62 |
Correct |
1972 ms |
80380 KB |
Output is correct |
63 |
Correct |
1348 ms |
87188 KB |
Output is correct |
64 |
Correct |
1332 ms |
68728 KB |
Output is correct |
65 |
Correct |
1660 ms |
72948 KB |
Output is correct |
66 |
Correct |
1624 ms |
74536 KB |
Output is correct |
67 |
Correct |
1640 ms |
75000 KB |
Output is correct |
68 |
Correct |
1684 ms |
79740 KB |
Output is correct |
69 |
Correct |
1735 ms |
80112 KB |
Output is correct |
70 |
Correct |
1673 ms |
78840 KB |
Output is correct |
71 |
Correct |
1733 ms |
78996 KB |
Output is correct |
72 |
Correct |
1680 ms |
78448 KB |
Output is correct |
73 |
Correct |
1213 ms |
68140 KB |
Output is correct |
74 |
Correct |
1201 ms |
67932 KB |
Output is correct |
75 |
Correct |
1206 ms |
68728 KB |
Output is correct |
76 |
Correct |
1184 ms |
67964 KB |
Output is correct |
77 |
Correct |
1212 ms |
77044 KB |
Output is correct |
78 |
Correct |
1502 ms |
94172 KB |
Output is correct |
79 |
Correct |
1048 ms |
80296 KB |
Output is correct |
80 |
Correct |
1458 ms |
89048 KB |
Output is correct |