#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, m, ans[N], t[4 * N], a[N], _l[N], _k[N];
vector <int> que[N];
stack <int> st;
void upd(int i, int l, int r, int pos, int val)
{
if(l == r)
{
t[i] = val;
return ;
}
int mid = l + r >> 1;
if(pos <= mid) upd(i << 1, l, mid, pos, val);
else upd(i << 1 | 1, mid + 1, r, pos, val);
t[i] = max(t[i << 1], t[i << 1 | 1]);
}
int get(int i, int l, int r, int u, int v)
{
if(l > v || u > r) return 0;
if(u <= l && r <= v) return t[i];
int mid = l + r >> 1;
return max(get(i << 1, l, mid, u, v), get(i << 1 | 1, mid + 1, r, u, v));
}
main ()
{
cin.tie(0)->sync_with_stdio(0);
if(fopen("task.inp", "r"))
{
freopen("task.inp", "r", stdin);
freopen("wa.out", "w", stdout);
}
cin >> n >> m;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= m; i++)
{
int r; cin >> _l[i] >> r >> _k[i];
que[r].push_back(i);
}
for(int i = 1; i <= n; i++)
{
while (!st.empty() && a[st.top()] <= a[i]) st.pop();
if(!st.empty()) upd(1, 1, n, st.top(), a[st.top()] + a[i]);
for(int j : que[i])
{
int l = _l[j], k = _k[j];
ans[j] = (get(1, 1, n, l, i) <= k) ? 1 : 0;
}
st.push(i);
}
for(int i = 1; i <= m; i++) cout << ans[i] << "\n";
}
Compilation message
sortbooks.cpp: In function 'void upd(int, int, int, int, int)':
sortbooks.cpp:16:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
16 | int mid = l + r >> 1;
| ~~^~~
sortbooks.cpp: In function 'int get(int, int, int, int, int)':
sortbooks.cpp:26:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
26 | int mid = l + r >> 1;
| ~~^~~
sortbooks.cpp: At global scope:
sortbooks.cpp:30:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
30 | main ()
| ^~~~
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:35:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | freopen("task.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:36:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | freopen("wa.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23884 KB |
Output is correct |
2 |
Correct |
11 ms |
23764 KB |
Output is correct |
3 |
Correct |
12 ms |
23784 KB |
Output is correct |
4 |
Correct |
11 ms |
23760 KB |
Output is correct |
5 |
Correct |
12 ms |
23764 KB |
Output is correct |
6 |
Correct |
12 ms |
23832 KB |
Output is correct |
7 |
Correct |
13 ms |
23832 KB |
Output is correct |
8 |
Correct |
12 ms |
23824 KB |
Output is correct |
9 |
Correct |
12 ms |
23764 KB |
Output is correct |
10 |
Correct |
14 ms |
23840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23884 KB |
Output is correct |
2 |
Correct |
11 ms |
23764 KB |
Output is correct |
3 |
Correct |
12 ms |
23784 KB |
Output is correct |
4 |
Correct |
11 ms |
23760 KB |
Output is correct |
5 |
Correct |
12 ms |
23764 KB |
Output is correct |
6 |
Correct |
12 ms |
23832 KB |
Output is correct |
7 |
Correct |
13 ms |
23832 KB |
Output is correct |
8 |
Correct |
12 ms |
23824 KB |
Output is correct |
9 |
Correct |
12 ms |
23764 KB |
Output is correct |
10 |
Correct |
14 ms |
23840 KB |
Output is correct |
11 |
Correct |
15 ms |
24012 KB |
Output is correct |
12 |
Correct |
14 ms |
24168 KB |
Output is correct |
13 |
Correct |
14 ms |
24148 KB |
Output is correct |
14 |
Correct |
16 ms |
24148 KB |
Output is correct |
15 |
Correct |
16 ms |
24148 KB |
Output is correct |
16 |
Correct |
15 ms |
24148 KB |
Output is correct |
17 |
Correct |
16 ms |
24124 KB |
Output is correct |
18 |
Correct |
15 ms |
24084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1380 ms |
99436 KB |
Output is correct |
2 |
Correct |
1349 ms |
100564 KB |
Output is correct |
3 |
Correct |
1407 ms |
100568 KB |
Output is correct |
4 |
Correct |
1398 ms |
100552 KB |
Output is correct |
5 |
Correct |
1148 ms |
92560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
30132 KB |
Output is correct |
2 |
Correct |
93 ms |
29452 KB |
Output is correct |
3 |
Correct |
87 ms |
28908 KB |
Output is correct |
4 |
Correct |
86 ms |
29056 KB |
Output is correct |
5 |
Correct |
81 ms |
29112 KB |
Output is correct |
6 |
Correct |
70 ms |
27956 KB |
Output is correct |
7 |
Correct |
70 ms |
27924 KB |
Output is correct |
8 |
Correct |
82 ms |
28816 KB |
Output is correct |
9 |
Correct |
46 ms |
27008 KB |
Output is correct |
10 |
Correct |
83 ms |
28740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23884 KB |
Output is correct |
2 |
Correct |
11 ms |
23764 KB |
Output is correct |
3 |
Correct |
12 ms |
23784 KB |
Output is correct |
4 |
Correct |
11 ms |
23760 KB |
Output is correct |
5 |
Correct |
12 ms |
23764 KB |
Output is correct |
6 |
Correct |
12 ms |
23832 KB |
Output is correct |
7 |
Correct |
13 ms |
23832 KB |
Output is correct |
8 |
Correct |
12 ms |
23824 KB |
Output is correct |
9 |
Correct |
12 ms |
23764 KB |
Output is correct |
10 |
Correct |
14 ms |
23840 KB |
Output is correct |
11 |
Correct |
15 ms |
24012 KB |
Output is correct |
12 |
Correct |
14 ms |
24168 KB |
Output is correct |
13 |
Correct |
14 ms |
24148 KB |
Output is correct |
14 |
Correct |
16 ms |
24148 KB |
Output is correct |
15 |
Correct |
16 ms |
24148 KB |
Output is correct |
16 |
Correct |
15 ms |
24148 KB |
Output is correct |
17 |
Correct |
16 ms |
24124 KB |
Output is correct |
18 |
Correct |
15 ms |
24084 KB |
Output is correct |
19 |
Correct |
213 ms |
39200 KB |
Output is correct |
20 |
Correct |
236 ms |
39244 KB |
Output is correct |
21 |
Correct |
201 ms |
37468 KB |
Output is correct |
22 |
Correct |
181 ms |
37284 KB |
Output is correct |
23 |
Correct |
210 ms |
37372 KB |
Output is correct |
24 |
Correct |
162 ms |
35052 KB |
Output is correct |
25 |
Correct |
150 ms |
35056 KB |
Output is correct |
26 |
Correct |
223 ms |
35960 KB |
Output is correct |
27 |
Correct |
221 ms |
35948 KB |
Output is correct |
28 |
Correct |
193 ms |
36172 KB |
Output is correct |
29 |
Correct |
216 ms |
37132 KB |
Output is correct |
30 |
Correct |
201 ms |
37108 KB |
Output is correct |
31 |
Correct |
182 ms |
37120 KB |
Output is correct |
32 |
Correct |
216 ms |
37060 KB |
Output is correct |
33 |
Correct |
187 ms |
37116 KB |
Output is correct |
34 |
Correct |
148 ms |
34740 KB |
Output is correct |
35 |
Correct |
157 ms |
34768 KB |
Output is correct |
36 |
Correct |
155 ms |
34452 KB |
Output is correct |
37 |
Correct |
143 ms |
34496 KB |
Output is correct |
38 |
Correct |
153 ms |
34740 KB |
Output is correct |
39 |
Correct |
168 ms |
36100 KB |
Output is correct |
40 |
Correct |
136 ms |
34092 KB |
Output is correct |
41 |
Correct |
162 ms |
35140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23884 KB |
Output is correct |
2 |
Correct |
11 ms |
23764 KB |
Output is correct |
3 |
Correct |
12 ms |
23784 KB |
Output is correct |
4 |
Correct |
11 ms |
23760 KB |
Output is correct |
5 |
Correct |
12 ms |
23764 KB |
Output is correct |
6 |
Correct |
12 ms |
23832 KB |
Output is correct |
7 |
Correct |
13 ms |
23832 KB |
Output is correct |
8 |
Correct |
12 ms |
23824 KB |
Output is correct |
9 |
Correct |
12 ms |
23764 KB |
Output is correct |
10 |
Correct |
14 ms |
23840 KB |
Output is correct |
11 |
Correct |
15 ms |
24012 KB |
Output is correct |
12 |
Correct |
14 ms |
24168 KB |
Output is correct |
13 |
Correct |
14 ms |
24148 KB |
Output is correct |
14 |
Correct |
16 ms |
24148 KB |
Output is correct |
15 |
Correct |
16 ms |
24148 KB |
Output is correct |
16 |
Correct |
15 ms |
24148 KB |
Output is correct |
17 |
Correct |
16 ms |
24124 KB |
Output is correct |
18 |
Correct |
15 ms |
24084 KB |
Output is correct |
19 |
Correct |
1380 ms |
99436 KB |
Output is correct |
20 |
Correct |
1349 ms |
100564 KB |
Output is correct |
21 |
Correct |
1407 ms |
100568 KB |
Output is correct |
22 |
Correct |
1398 ms |
100552 KB |
Output is correct |
23 |
Correct |
1148 ms |
92560 KB |
Output is correct |
24 |
Correct |
95 ms |
30132 KB |
Output is correct |
25 |
Correct |
93 ms |
29452 KB |
Output is correct |
26 |
Correct |
87 ms |
28908 KB |
Output is correct |
27 |
Correct |
86 ms |
29056 KB |
Output is correct |
28 |
Correct |
81 ms |
29112 KB |
Output is correct |
29 |
Correct |
70 ms |
27956 KB |
Output is correct |
30 |
Correct |
70 ms |
27924 KB |
Output is correct |
31 |
Correct |
82 ms |
28816 KB |
Output is correct |
32 |
Correct |
46 ms |
27008 KB |
Output is correct |
33 |
Correct |
83 ms |
28740 KB |
Output is correct |
34 |
Correct |
213 ms |
39200 KB |
Output is correct |
35 |
Correct |
236 ms |
39244 KB |
Output is correct |
36 |
Correct |
201 ms |
37468 KB |
Output is correct |
37 |
Correct |
181 ms |
37284 KB |
Output is correct |
38 |
Correct |
210 ms |
37372 KB |
Output is correct |
39 |
Correct |
162 ms |
35052 KB |
Output is correct |
40 |
Correct |
150 ms |
35056 KB |
Output is correct |
41 |
Correct |
223 ms |
35960 KB |
Output is correct |
42 |
Correct |
221 ms |
35948 KB |
Output is correct |
43 |
Correct |
193 ms |
36172 KB |
Output is correct |
44 |
Correct |
216 ms |
37132 KB |
Output is correct |
45 |
Correct |
201 ms |
37108 KB |
Output is correct |
46 |
Correct |
182 ms |
37120 KB |
Output is correct |
47 |
Correct |
216 ms |
37060 KB |
Output is correct |
48 |
Correct |
187 ms |
37116 KB |
Output is correct |
49 |
Correct |
148 ms |
34740 KB |
Output is correct |
50 |
Correct |
157 ms |
34768 KB |
Output is correct |
51 |
Correct |
155 ms |
34452 KB |
Output is correct |
52 |
Correct |
143 ms |
34496 KB |
Output is correct |
53 |
Correct |
153 ms |
34740 KB |
Output is correct |
54 |
Correct |
168 ms |
36100 KB |
Output is correct |
55 |
Correct |
136 ms |
34092 KB |
Output is correct |
56 |
Correct |
162 ms |
35140 KB |
Output is correct |
57 |
Correct |
1552 ms |
99388 KB |
Output is correct |
58 |
Correct |
1425 ms |
99648 KB |
Output is correct |
59 |
Correct |
1454 ms |
95280 KB |
Output is correct |
60 |
Correct |
1344 ms |
95312 KB |
Output is correct |
61 |
Correct |
1277 ms |
95244 KB |
Output is correct |
62 |
Correct |
1326 ms |
95372 KB |
Output is correct |
63 |
Correct |
882 ms |
79444 KB |
Output is correct |
64 |
Correct |
938 ms |
79332 KB |
Output is correct |
65 |
Correct |
1077 ms |
86528 KB |
Output is correct |
66 |
Correct |
1052 ms |
86524 KB |
Output is correct |
67 |
Correct |
1070 ms |
86844 KB |
Output is correct |
68 |
Correct |
1162 ms |
91280 KB |
Output is correct |
69 |
Correct |
1273 ms |
91260 KB |
Output is correct |
70 |
Correct |
1113 ms |
90592 KB |
Output is correct |
71 |
Correct |
1136 ms |
90464 KB |
Output is correct |
72 |
Correct |
1136 ms |
90452 KB |
Output is correct |
73 |
Correct |
826 ms |
77404 KB |
Output is correct |
74 |
Correct |
873 ms |
78304 KB |
Output is correct |
75 |
Correct |
778 ms |
77376 KB |
Output is correct |
76 |
Correct |
841 ms |
77372 KB |
Output is correct |
77 |
Correct |
785 ms |
77256 KB |
Output is correct |
78 |
Correct |
1010 ms |
86048 KB |
Output is correct |
79 |
Correct |
713 ms |
74444 KB |
Output is correct |
80 |
Correct |
1031 ms |
81284 KB |
Output is correct |