#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <stack>
#define PB push_back
using namespace std;
const int N = 1e6 + 500;
const int OFF = (1 << 20);
int T[2 * OFF], prop[2 * OFF];
int n, q, qL[N], qR[N], qK[N], qA[N], A[N];
vector < int > v[N];
void refresh(int x){
if(!prop[x]) return;
T[x] += prop[x];
if(x < OFF){
prop[2 * x] += prop[x];
prop[2 * x + 1] += prop[x];
}
prop[x] = 0;
}
void update(int i, int a, int b, int lo, int hi,int x){
refresh(i);
if(lo <= a && b <= hi){
prop[i] += x; refresh(i);
return;
}
if(a > hi || b < lo) return;
update(2 * i, a, (a + b) / 2, lo, hi, x);
update(2 * i + 1, (a + b) / 2 + 1, b, lo, hi, x);
T[i] = max(T[2 * i], T[2 * i + 1]);
}
int query(int i, int a, int b, int lo, int hi){
refresh(i);
if(lo <= a && b <= hi) return T[i];
if(a > hi || b < lo) return 0;
return max(query(2 * i, a, (a + b) / 2, lo, hi), query(2 * i + 1, (a + b) / 2 + 1, b, lo, hi));
}
int main(){
scanf("%d%d", &n, &q);
for(int i = 0;i < n;i++)
scanf("%d", A + i);
for(int i = 0;i < q;i++){
scanf("%d%d%d", qL + i, qR + i, qK + i);
qL[i]--, qR[i]--; v[qL[i]].PB(i);
}
stack < int > S;
for(int i = n - 1;i >= 0;i--){
while(!S.empty () && A[i] > A[S.top()]){
int vrh = S.top(); S.pop();
update(1, 0, OFF - 1, vrh + 1, (S.empty() ? n : S.top()) - 1, A[i] - A[vrh]);
update(1, 0, OFF - 1, vrh, vrh, A[i] + A[vrh]);
}
S.push(i);
for(int x : v[i]){
qA[x] = query(1, 0, OFF - 1, qL[x], qR[x]);
}
}
for(int i = 0;i < q;i++)
printf("%d\n", qA[i] <= qK[i]);
}
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:48:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
48 | scanf("%d%d", &n, &q);
| ~~~~~^~~~~~~~~~~~~~~~
sortbooks.cpp:50:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
50 | scanf("%d", A + i);
| ~~~~~^~~~~~~~~~~~~
sortbooks.cpp:52:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
52 | scanf("%d%d%d", qL + i, qR + i, qK + i);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23916 KB |
Output is correct |
2 |
Correct |
15 ms |
23916 KB |
Output is correct |
3 |
Correct |
16 ms |
23916 KB |
Output is correct |
4 |
Correct |
16 ms |
23916 KB |
Output is correct |
5 |
Correct |
16 ms |
23916 KB |
Output is correct |
6 |
Correct |
17 ms |
24044 KB |
Output is correct |
7 |
Correct |
17 ms |
24044 KB |
Output is correct |
8 |
Correct |
17 ms |
24044 KB |
Output is correct |
9 |
Correct |
16 ms |
23916 KB |
Output is correct |
10 |
Correct |
16 ms |
24044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23916 KB |
Output is correct |
2 |
Correct |
15 ms |
23916 KB |
Output is correct |
3 |
Correct |
16 ms |
23916 KB |
Output is correct |
4 |
Correct |
16 ms |
23916 KB |
Output is correct |
5 |
Correct |
16 ms |
23916 KB |
Output is correct |
6 |
Correct |
17 ms |
24044 KB |
Output is correct |
7 |
Correct |
17 ms |
24044 KB |
Output is correct |
8 |
Correct |
17 ms |
24044 KB |
Output is correct |
9 |
Correct |
16 ms |
23916 KB |
Output is correct |
10 |
Correct |
16 ms |
24044 KB |
Output is correct |
11 |
Correct |
24 ms |
24172 KB |
Output is correct |
12 |
Correct |
23 ms |
24300 KB |
Output is correct |
13 |
Correct |
24 ms |
24300 KB |
Output is correct |
14 |
Correct |
26 ms |
24428 KB |
Output is correct |
15 |
Correct |
26 ms |
24428 KB |
Output is correct |
16 |
Correct |
22 ms |
24300 KB |
Output is correct |
17 |
Correct |
21 ms |
24300 KB |
Output is correct |
18 |
Correct |
23 ms |
24300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2926 ms |
94032 KB |
Output is correct |
2 |
Correct |
2916 ms |
112048 KB |
Output is correct |
3 |
Correct |
2891 ms |
111980 KB |
Output is correct |
4 |
Correct |
2865 ms |
112024 KB |
Output is correct |
5 |
Correct |
1806 ms |
100460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
233 ms |
31724 KB |
Output is correct |
2 |
Correct |
214 ms |
30700 KB |
Output is correct |
3 |
Correct |
143 ms |
30188 KB |
Output is correct |
4 |
Correct |
146 ms |
30316 KB |
Output is correct |
5 |
Correct |
147 ms |
30444 KB |
Output is correct |
6 |
Correct |
131 ms |
29036 KB |
Output is correct |
7 |
Correct |
131 ms |
29036 KB |
Output is correct |
8 |
Correct |
182 ms |
30184 KB |
Output is correct |
9 |
Correct |
91 ms |
27628 KB |
Output is correct |
10 |
Correct |
187 ms |
29972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23916 KB |
Output is correct |
2 |
Correct |
15 ms |
23916 KB |
Output is correct |
3 |
Correct |
16 ms |
23916 KB |
Output is correct |
4 |
Correct |
16 ms |
23916 KB |
Output is correct |
5 |
Correct |
16 ms |
23916 KB |
Output is correct |
6 |
Correct |
17 ms |
24044 KB |
Output is correct |
7 |
Correct |
17 ms |
24044 KB |
Output is correct |
8 |
Correct |
17 ms |
24044 KB |
Output is correct |
9 |
Correct |
16 ms |
23916 KB |
Output is correct |
10 |
Correct |
16 ms |
24044 KB |
Output is correct |
11 |
Correct |
24 ms |
24172 KB |
Output is correct |
12 |
Correct |
23 ms |
24300 KB |
Output is correct |
13 |
Correct |
24 ms |
24300 KB |
Output is correct |
14 |
Correct |
26 ms |
24428 KB |
Output is correct |
15 |
Correct |
26 ms |
24428 KB |
Output is correct |
16 |
Correct |
22 ms |
24300 KB |
Output is correct |
17 |
Correct |
21 ms |
24300 KB |
Output is correct |
18 |
Correct |
23 ms |
24300 KB |
Output is correct |
19 |
Correct |
511 ms |
42220 KB |
Output is correct |
20 |
Correct |
517 ms |
42092 KB |
Output is correct |
21 |
Correct |
443 ms |
39532 KB |
Output is correct |
22 |
Correct |
440 ms |
39660 KB |
Output is correct |
23 |
Correct |
441 ms |
39660 KB |
Output is correct |
24 |
Correct |
268 ms |
36844 KB |
Output is correct |
25 |
Correct |
295 ms |
36844 KB |
Output is correct |
26 |
Correct |
319 ms |
37992 KB |
Output is correct |
27 |
Correct |
301 ms |
37868 KB |
Output is correct |
28 |
Correct |
299 ms |
38380 KB |
Output is correct |
29 |
Correct |
323 ms |
39788 KB |
Output is correct |
30 |
Correct |
317 ms |
39532 KB |
Output is correct |
31 |
Correct |
319 ms |
39532 KB |
Output is correct |
32 |
Correct |
317 ms |
39444 KB |
Output is correct |
33 |
Correct |
321 ms |
39532 KB |
Output is correct |
34 |
Correct |
263 ms |
36460 KB |
Output is correct |
35 |
Correct |
263 ms |
36460 KB |
Output is correct |
36 |
Correct |
262 ms |
36204 KB |
Output is correct |
37 |
Correct |
271 ms |
36204 KB |
Output is correct |
38 |
Correct |
261 ms |
36460 KB |
Output is correct |
39 |
Correct |
326 ms |
37608 KB |
Output is correct |
40 |
Correct |
232 ms |
35428 KB |
Output is correct |
41 |
Correct |
350 ms |
37476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23916 KB |
Output is correct |
2 |
Correct |
15 ms |
23916 KB |
Output is correct |
3 |
Correct |
16 ms |
23916 KB |
Output is correct |
4 |
Correct |
16 ms |
23916 KB |
Output is correct |
5 |
Correct |
16 ms |
23916 KB |
Output is correct |
6 |
Correct |
17 ms |
24044 KB |
Output is correct |
7 |
Correct |
17 ms |
24044 KB |
Output is correct |
8 |
Correct |
17 ms |
24044 KB |
Output is correct |
9 |
Correct |
16 ms |
23916 KB |
Output is correct |
10 |
Correct |
16 ms |
24044 KB |
Output is correct |
11 |
Correct |
24 ms |
24172 KB |
Output is correct |
12 |
Correct |
23 ms |
24300 KB |
Output is correct |
13 |
Correct |
24 ms |
24300 KB |
Output is correct |
14 |
Correct |
26 ms |
24428 KB |
Output is correct |
15 |
Correct |
26 ms |
24428 KB |
Output is correct |
16 |
Correct |
22 ms |
24300 KB |
Output is correct |
17 |
Correct |
21 ms |
24300 KB |
Output is correct |
18 |
Correct |
23 ms |
24300 KB |
Output is correct |
19 |
Correct |
2926 ms |
94032 KB |
Output is correct |
20 |
Correct |
2916 ms |
112048 KB |
Output is correct |
21 |
Correct |
2891 ms |
111980 KB |
Output is correct |
22 |
Correct |
2865 ms |
112024 KB |
Output is correct |
23 |
Correct |
1806 ms |
100460 KB |
Output is correct |
24 |
Correct |
233 ms |
31724 KB |
Output is correct |
25 |
Correct |
214 ms |
30700 KB |
Output is correct |
26 |
Correct |
143 ms |
30188 KB |
Output is correct |
27 |
Correct |
146 ms |
30316 KB |
Output is correct |
28 |
Correct |
147 ms |
30444 KB |
Output is correct |
29 |
Correct |
131 ms |
29036 KB |
Output is correct |
30 |
Correct |
131 ms |
29036 KB |
Output is correct |
31 |
Correct |
182 ms |
30184 KB |
Output is correct |
32 |
Correct |
91 ms |
27628 KB |
Output is correct |
33 |
Correct |
187 ms |
29972 KB |
Output is correct |
34 |
Correct |
511 ms |
42220 KB |
Output is correct |
35 |
Correct |
517 ms |
42092 KB |
Output is correct |
36 |
Correct |
443 ms |
39532 KB |
Output is correct |
37 |
Correct |
440 ms |
39660 KB |
Output is correct |
38 |
Correct |
441 ms |
39660 KB |
Output is correct |
39 |
Correct |
268 ms |
36844 KB |
Output is correct |
40 |
Correct |
295 ms |
36844 KB |
Output is correct |
41 |
Correct |
319 ms |
37992 KB |
Output is correct |
42 |
Correct |
301 ms |
37868 KB |
Output is correct |
43 |
Correct |
299 ms |
38380 KB |
Output is correct |
44 |
Correct |
323 ms |
39788 KB |
Output is correct |
45 |
Correct |
317 ms |
39532 KB |
Output is correct |
46 |
Correct |
319 ms |
39532 KB |
Output is correct |
47 |
Correct |
317 ms |
39444 KB |
Output is correct |
48 |
Correct |
321 ms |
39532 KB |
Output is correct |
49 |
Correct |
263 ms |
36460 KB |
Output is correct |
50 |
Correct |
263 ms |
36460 KB |
Output is correct |
51 |
Correct |
262 ms |
36204 KB |
Output is correct |
52 |
Correct |
271 ms |
36204 KB |
Output is correct |
53 |
Correct |
261 ms |
36460 KB |
Output is correct |
54 |
Correct |
326 ms |
37608 KB |
Output is correct |
55 |
Correct |
232 ms |
35428 KB |
Output is correct |
56 |
Correct |
350 ms |
37476 KB |
Output is correct |
57 |
Correct |
2863 ms |
114852 KB |
Output is correct |
58 |
Correct |
2863 ms |
114544 KB |
Output is correct |
59 |
Correct |
2694 ms |
108968 KB |
Output is correct |
60 |
Correct |
2675 ms |
108876 KB |
Output is correct |
61 |
Correct |
2769 ms |
108908 KB |
Output is correct |
62 |
Correct |
2784 ms |
108788 KB |
Output is correct |
63 |
Correct |
1418 ms |
86952 KB |
Output is correct |
64 |
Correct |
1391 ms |
86892 KB |
Output is correct |
65 |
Correct |
1756 ms |
96576 KB |
Output is correct |
66 |
Correct |
1739 ms |
96492 KB |
Output is correct |
67 |
Correct |
1731 ms |
97128 KB |
Output is correct |
68 |
Correct |
1799 ms |
103020 KB |
Output is correct |
69 |
Correct |
1780 ms |
102892 KB |
Output is correct |
70 |
Correct |
1791 ms |
102120 KB |
Output is correct |
71 |
Correct |
1810 ms |
102472 KB |
Output is correct |
72 |
Correct |
1782 ms |
102328 KB |
Output is correct |
73 |
Correct |
1323 ms |
84776 KB |
Output is correct |
74 |
Correct |
1332 ms |
85636 KB |
Output is correct |
75 |
Correct |
1318 ms |
84764 KB |
Output is correct |
76 |
Correct |
1339 ms |
84788 KB |
Output is correct |
77 |
Correct |
1310 ms |
84844 KB |
Output is correct |
78 |
Correct |
1799 ms |
93536 KB |
Output is correct |
79 |
Correct |
1153 ms |
79708 KB |
Output is correct |
80 |
Correct |
2033 ms |
94176 KB |
Output is correct |