#include <bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define all(s) s.begin(),s.end()
//#define int long long
using namespace std;
const int N = (1e6 + 12);
const int mod = (1e9 + 7);
const int INF = (0x3f3f3f3f);
int a[N], pos[N], l[N], r[N], k[N], t[N * 4], ans[N];
vector<int > vec[N];
void update(int v,int tl,int tr,int pos,int val){
if(tl == tr){
t[v] = val;
return;
}
int mid = (tl + tr) >> 1;
if(pos <= mid){
update(v + v, tl, mid, pos, val);
}
else{
update(v + v + 1, mid + 1, tr, pos, val);
}
t[v] = max(t[v + v], t[v + v + 1]);
}
int get(int v,int tl,int tr,int ll,int rr){
if(tl > rr || tr < ll){
return 0;
}
if(ll <= tl && tr <= rr){
return t[v];
}
int mid = (tl + tr) >> 1;
return max(get(v + v, tl, mid, ll, rr), get(v + v + 1, mid + 1, tr, ll, rr));
}
main()
{
int n, m;
scanf("%d%d", &n, &m);
for(int i = 1;i <= n; i++){
scanf("%d", &a[i]);
pos[i] = i - 1;
while(pos[i] && a[pos[i]] <= a[i]){
pos[i] = pos[pos[i]];
}
}
for(int i = 1;i <= m; i++){
scanf("%d%d%d", &l[i], &r[i], &k[i]);
vec[r[i]].pb(i);
}
for(int i = 1;i <= n; i++){
if(pos[i]){
update(1, 1, n, pos[i], a[i] + a[pos[i]]);
}
for(auto to : vec[i]){
ans[to] = (get(1, 1, n, l[to], r[to]) <= k[to] ? 1 : 0);
}
}
for(int i = 1;i <= m; i++){
printf("%d\n", ans[i]);
}
}
Compilation message
sortbooks.cpp:44:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main()
^
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:47:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~
sortbooks.cpp:49:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &a[i]);
~~~~~^~~~~~~~~~~~~
sortbooks.cpp:56:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &l[i], &r[i], &k[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
23928 KB |
Output is correct |
2 |
Correct |
23 ms |
23928 KB |
Output is correct |
3 |
Correct |
24 ms |
23800 KB |
Output is correct |
4 |
Correct |
23 ms |
23928 KB |
Output is correct |
5 |
Correct |
23 ms |
23800 KB |
Output is correct |
6 |
Correct |
24 ms |
23816 KB |
Output is correct |
7 |
Correct |
24 ms |
23928 KB |
Output is correct |
8 |
Correct |
24 ms |
24056 KB |
Output is correct |
9 |
Correct |
24 ms |
23928 KB |
Output is correct |
10 |
Correct |
24 ms |
23800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
23928 KB |
Output is correct |
2 |
Correct |
23 ms |
23928 KB |
Output is correct |
3 |
Correct |
24 ms |
23800 KB |
Output is correct |
4 |
Correct |
23 ms |
23928 KB |
Output is correct |
5 |
Correct |
23 ms |
23800 KB |
Output is correct |
6 |
Correct |
24 ms |
23816 KB |
Output is correct |
7 |
Correct |
24 ms |
23928 KB |
Output is correct |
8 |
Correct |
24 ms |
24056 KB |
Output is correct |
9 |
Correct |
24 ms |
23928 KB |
Output is correct |
10 |
Correct |
24 ms |
23800 KB |
Output is correct |
11 |
Correct |
26 ms |
24056 KB |
Output is correct |
12 |
Correct |
28 ms |
24184 KB |
Output is correct |
13 |
Correct |
28 ms |
24184 KB |
Output is correct |
14 |
Correct |
29 ms |
24312 KB |
Output is correct |
15 |
Correct |
30 ms |
24312 KB |
Output is correct |
16 |
Correct |
28 ms |
24184 KB |
Output is correct |
17 |
Correct |
28 ms |
24184 KB |
Output is correct |
18 |
Correct |
28 ms |
24184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2068 ms |
75628 KB |
Output is correct |
2 |
Correct |
2070 ms |
79440 KB |
Output is correct |
3 |
Correct |
2134 ms |
79536 KB |
Output is correct |
4 |
Correct |
2048 ms |
79608 KB |
Output is correct |
5 |
Correct |
1677 ms |
71228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
157 ms |
29048 KB |
Output is correct |
2 |
Correct |
141 ms |
30300 KB |
Output is correct |
3 |
Correct |
129 ms |
29688 KB |
Output is correct |
4 |
Correct |
134 ms |
29944 KB |
Output is correct |
5 |
Correct |
131 ms |
29944 KB |
Output is correct |
6 |
Correct |
106 ms |
28816 KB |
Output is correct |
7 |
Correct |
106 ms |
28792 KB |
Output is correct |
8 |
Correct |
124 ms |
29640 KB |
Output is correct |
9 |
Correct |
74 ms |
27420 KB |
Output is correct |
10 |
Correct |
123 ms |
29684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
23928 KB |
Output is correct |
2 |
Correct |
23 ms |
23928 KB |
Output is correct |
3 |
Correct |
24 ms |
23800 KB |
Output is correct |
4 |
Correct |
23 ms |
23928 KB |
Output is correct |
5 |
Correct |
23 ms |
23800 KB |
Output is correct |
6 |
Correct |
24 ms |
23816 KB |
Output is correct |
7 |
Correct |
24 ms |
23928 KB |
Output is correct |
8 |
Correct |
24 ms |
24056 KB |
Output is correct |
9 |
Correct |
24 ms |
23928 KB |
Output is correct |
10 |
Correct |
24 ms |
23800 KB |
Output is correct |
11 |
Correct |
26 ms |
24056 KB |
Output is correct |
12 |
Correct |
28 ms |
24184 KB |
Output is correct |
13 |
Correct |
28 ms |
24184 KB |
Output is correct |
14 |
Correct |
29 ms |
24312 KB |
Output is correct |
15 |
Correct |
30 ms |
24312 KB |
Output is correct |
16 |
Correct |
28 ms |
24184 KB |
Output is correct |
17 |
Correct |
28 ms |
24184 KB |
Output is correct |
18 |
Correct |
28 ms |
24184 KB |
Output is correct |
19 |
Correct |
353 ms |
40908 KB |
Output is correct |
20 |
Correct |
350 ms |
41012 KB |
Output is correct |
21 |
Correct |
297 ms |
39036 KB |
Output is correct |
22 |
Correct |
285 ms |
39084 KB |
Output is correct |
23 |
Correct |
291 ms |
39116 KB |
Output is correct |
24 |
Correct |
237 ms |
36600 KB |
Output is correct |
25 |
Correct |
243 ms |
36708 KB |
Output is correct |
26 |
Correct |
260 ms |
37624 KB |
Output is correct |
27 |
Correct |
273 ms |
37624 KB |
Output is correct |
28 |
Correct |
277 ms |
37892 KB |
Output is correct |
29 |
Correct |
288 ms |
38776 KB |
Output is correct |
30 |
Correct |
294 ms |
38848 KB |
Output is correct |
31 |
Correct |
298 ms |
38904 KB |
Output is correct |
32 |
Correct |
306 ms |
38776 KB |
Output is correct |
33 |
Correct |
355 ms |
38884 KB |
Output is correct |
34 |
Correct |
254 ms |
36472 KB |
Output is correct |
35 |
Correct |
223 ms |
36344 KB |
Output is correct |
36 |
Correct |
234 ms |
36240 KB |
Output is correct |
37 |
Correct |
217 ms |
36196 KB |
Output is correct |
38 |
Correct |
223 ms |
36348 KB |
Output is correct |
39 |
Correct |
265 ms |
37744 KB |
Output is correct |
40 |
Correct |
209 ms |
35572 KB |
Output is correct |
41 |
Correct |
252 ms |
36892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
23928 KB |
Output is correct |
2 |
Correct |
23 ms |
23928 KB |
Output is correct |
3 |
Correct |
24 ms |
23800 KB |
Output is correct |
4 |
Correct |
23 ms |
23928 KB |
Output is correct |
5 |
Correct |
23 ms |
23800 KB |
Output is correct |
6 |
Correct |
24 ms |
23816 KB |
Output is correct |
7 |
Correct |
24 ms |
23928 KB |
Output is correct |
8 |
Correct |
24 ms |
24056 KB |
Output is correct |
9 |
Correct |
24 ms |
23928 KB |
Output is correct |
10 |
Correct |
24 ms |
23800 KB |
Output is correct |
11 |
Correct |
26 ms |
24056 KB |
Output is correct |
12 |
Correct |
28 ms |
24184 KB |
Output is correct |
13 |
Correct |
28 ms |
24184 KB |
Output is correct |
14 |
Correct |
29 ms |
24312 KB |
Output is correct |
15 |
Correct |
30 ms |
24312 KB |
Output is correct |
16 |
Correct |
28 ms |
24184 KB |
Output is correct |
17 |
Correct |
28 ms |
24184 KB |
Output is correct |
18 |
Correct |
28 ms |
24184 KB |
Output is correct |
19 |
Correct |
2068 ms |
75628 KB |
Output is correct |
20 |
Correct |
2070 ms |
79440 KB |
Output is correct |
21 |
Correct |
2134 ms |
79536 KB |
Output is correct |
22 |
Correct |
2048 ms |
79608 KB |
Output is correct |
23 |
Correct |
1677 ms |
71228 KB |
Output is correct |
24 |
Correct |
157 ms |
29048 KB |
Output is correct |
25 |
Correct |
141 ms |
30300 KB |
Output is correct |
26 |
Correct |
129 ms |
29688 KB |
Output is correct |
27 |
Correct |
134 ms |
29944 KB |
Output is correct |
28 |
Correct |
131 ms |
29944 KB |
Output is correct |
29 |
Correct |
106 ms |
28816 KB |
Output is correct |
30 |
Correct |
106 ms |
28792 KB |
Output is correct |
31 |
Correct |
124 ms |
29640 KB |
Output is correct |
32 |
Correct |
74 ms |
27420 KB |
Output is correct |
33 |
Correct |
123 ms |
29684 KB |
Output is correct |
34 |
Correct |
353 ms |
40908 KB |
Output is correct |
35 |
Correct |
350 ms |
41012 KB |
Output is correct |
36 |
Correct |
297 ms |
39036 KB |
Output is correct |
37 |
Correct |
285 ms |
39084 KB |
Output is correct |
38 |
Correct |
291 ms |
39116 KB |
Output is correct |
39 |
Correct |
237 ms |
36600 KB |
Output is correct |
40 |
Correct |
243 ms |
36708 KB |
Output is correct |
41 |
Correct |
260 ms |
37624 KB |
Output is correct |
42 |
Correct |
273 ms |
37624 KB |
Output is correct |
43 |
Correct |
277 ms |
37892 KB |
Output is correct |
44 |
Correct |
288 ms |
38776 KB |
Output is correct |
45 |
Correct |
294 ms |
38848 KB |
Output is correct |
46 |
Correct |
298 ms |
38904 KB |
Output is correct |
47 |
Correct |
306 ms |
38776 KB |
Output is correct |
48 |
Correct |
355 ms |
38884 KB |
Output is correct |
49 |
Correct |
254 ms |
36472 KB |
Output is correct |
50 |
Correct |
223 ms |
36344 KB |
Output is correct |
51 |
Correct |
234 ms |
36240 KB |
Output is correct |
52 |
Correct |
217 ms |
36196 KB |
Output is correct |
53 |
Correct |
223 ms |
36348 KB |
Output is correct |
54 |
Correct |
265 ms |
37744 KB |
Output is correct |
55 |
Correct |
209 ms |
35572 KB |
Output is correct |
56 |
Correct |
252 ms |
36892 KB |
Output is correct |
57 |
Correct |
2072 ms |
100100 KB |
Output is correct |
58 |
Correct |
2076 ms |
107284 KB |
Output is correct |
59 |
Correct |
1983 ms |
103112 KB |
Output is correct |
60 |
Correct |
2066 ms |
88952 KB |
Output is correct |
61 |
Correct |
1966 ms |
103080 KB |
Output is correct |
62 |
Correct |
1947 ms |
84796 KB |
Output is correct |
63 |
Correct |
1291 ms |
64688 KB |
Output is correct |
64 |
Correct |
1288 ms |
86932 KB |
Output is correct |
65 |
Correct |
1603 ms |
77160 KB |
Output is correct |
66 |
Correct |
1595 ms |
94396 KB |
Output is correct |
67 |
Correct |
1599 ms |
94684 KB |
Output is correct |
68 |
Correct |
1667 ms |
99008 KB |
Output is correct |
69 |
Correct |
1666 ms |
90352 KB |
Output is correct |
70 |
Correct |
1636 ms |
98536 KB |
Output is correct |
71 |
Correct |
1669 ms |
98452 KB |
Output is correct |
72 |
Correct |
1656 ms |
86024 KB |
Output is correct |
73 |
Correct |
1195 ms |
85204 KB |
Output is correct |
74 |
Correct |
1192 ms |
86004 KB |
Output is correct |
75 |
Correct |
1174 ms |
85296 KB |
Output is correct |
76 |
Correct |
1192 ms |
85200 KB |
Output is correct |
77 |
Correct |
1219 ms |
84720 KB |
Output is correct |
78 |
Correct |
1434 ms |
82716 KB |
Output is correct |
79 |
Correct |
1031 ms |
80364 KB |
Output is correct |
80 |
Correct |
1414 ms |
82308 KB |
Output is correct |