#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const long long inf = 2000000000;
#define ll long long
#define int long long
#define F first
#define S second
#define pb push_back
int n, m, a[N], l[N], r[N], k[N];
int t[4*N], mx;
bool ans[N];
vector<int> v[N];
void update(int pos, int val, int tl = 1, int tr = n, int v = 1){
if(tl == tr) {
t[v] = max(t[v], val);
}
else{
int tm = (tl + tr) / 2;
if(pos <= tm) update(pos, val, tl, tm, v * 2);
else update(pos, val, tm + 1, tr, v * 2 + 1);
t[v] = max(t[v * 2], t[v * 2 + 1]);
}
}
int get(int v, int tl, int tr, int l, int r){
if(l <= tl && tr <= r) return t[v];
if(l > tr || r < tl) return 0;
int tm = (tl + tr) / 2;
return max(get(v * 2, tl, tm, l, r), get(v * 2 + 1, tm + 1, tr, l, r));
}
main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; ++i){
cin >> a[i];
}
for(int i = 1; i <= m; ++i){
cin >> l[i] >> r[i] >> k[i];
v[r[i]].pb(i);
}
stack<int> st;
st.push(0);
a[0] = inf;
for(int i = 1; i <= n; ++i){
while(a[st.top()] <= a[i]) st.pop();
if(st.top() != 0) update(st.top(), a[st.top()] + a[i]);
st.push(i);
for(auto to : v[i]){
mx = get(1, 1, n, l[to], i);
if(mx <= k[to]) ans[to] = 1;
}
}
for(int i = 1; i <= m; ++i){
cout << ans[i] << '\n';
}
return 0;
}
Compilation message
sortbooks.cpp:31:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
31 | main()
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23756 KB |
Output is correct |
2 |
Correct |
12 ms |
23884 KB |
Output is correct |
3 |
Correct |
11 ms |
23808 KB |
Output is correct |
4 |
Correct |
12 ms |
23784 KB |
Output is correct |
5 |
Correct |
11 ms |
23800 KB |
Output is correct |
6 |
Correct |
13 ms |
23884 KB |
Output is correct |
7 |
Correct |
12 ms |
23812 KB |
Output is correct |
8 |
Correct |
11 ms |
23884 KB |
Output is correct |
9 |
Correct |
12 ms |
23808 KB |
Output is correct |
10 |
Correct |
11 ms |
23884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23756 KB |
Output is correct |
2 |
Correct |
12 ms |
23884 KB |
Output is correct |
3 |
Correct |
11 ms |
23808 KB |
Output is correct |
4 |
Correct |
12 ms |
23784 KB |
Output is correct |
5 |
Correct |
11 ms |
23800 KB |
Output is correct |
6 |
Correct |
13 ms |
23884 KB |
Output is correct |
7 |
Correct |
12 ms |
23812 KB |
Output is correct |
8 |
Correct |
11 ms |
23884 KB |
Output is correct |
9 |
Correct |
12 ms |
23808 KB |
Output is correct |
10 |
Correct |
11 ms |
23884 KB |
Output is correct |
11 |
Correct |
14 ms |
24072 KB |
Output is correct |
12 |
Correct |
18 ms |
24176 KB |
Output is correct |
13 |
Correct |
17 ms |
24268 KB |
Output is correct |
14 |
Correct |
19 ms |
24320 KB |
Output is correct |
15 |
Correct |
17 ms |
24400 KB |
Output is correct |
16 |
Correct |
16 ms |
24268 KB |
Output is correct |
17 |
Correct |
14 ms |
24204 KB |
Output is correct |
18 |
Correct |
14 ms |
24180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1424 ms |
107364 KB |
Output is correct |
2 |
Correct |
1415 ms |
107172 KB |
Output is correct |
3 |
Correct |
1379 ms |
107316 KB |
Output is correct |
4 |
Correct |
1421 ms |
106896 KB |
Output is correct |
5 |
Correct |
1154 ms |
91932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
100 ms |
33156 KB |
Output is correct |
2 |
Correct |
91 ms |
32544 KB |
Output is correct |
3 |
Correct |
84 ms |
30848 KB |
Output is correct |
4 |
Correct |
83 ms |
31056 KB |
Output is correct |
5 |
Correct |
89 ms |
31108 KB |
Output is correct |
6 |
Correct |
73 ms |
30148 KB |
Output is correct |
7 |
Correct |
76 ms |
30112 KB |
Output is correct |
8 |
Correct |
80 ms |
30620 KB |
Output is correct |
9 |
Correct |
49 ms |
28736 KB |
Output is correct |
10 |
Correct |
88 ms |
30620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23756 KB |
Output is correct |
2 |
Correct |
12 ms |
23884 KB |
Output is correct |
3 |
Correct |
11 ms |
23808 KB |
Output is correct |
4 |
Correct |
12 ms |
23784 KB |
Output is correct |
5 |
Correct |
11 ms |
23800 KB |
Output is correct |
6 |
Correct |
13 ms |
23884 KB |
Output is correct |
7 |
Correct |
12 ms |
23812 KB |
Output is correct |
8 |
Correct |
11 ms |
23884 KB |
Output is correct |
9 |
Correct |
12 ms |
23808 KB |
Output is correct |
10 |
Correct |
11 ms |
23884 KB |
Output is correct |
11 |
Correct |
14 ms |
24072 KB |
Output is correct |
12 |
Correct |
18 ms |
24176 KB |
Output is correct |
13 |
Correct |
17 ms |
24268 KB |
Output is correct |
14 |
Correct |
19 ms |
24320 KB |
Output is correct |
15 |
Correct |
17 ms |
24400 KB |
Output is correct |
16 |
Correct |
16 ms |
24268 KB |
Output is correct |
17 |
Correct |
14 ms |
24204 KB |
Output is correct |
18 |
Correct |
14 ms |
24180 KB |
Output is correct |
19 |
Correct |
224 ms |
45072 KB |
Output is correct |
20 |
Correct |
271 ms |
45112 KB |
Output is correct |
21 |
Correct |
198 ms |
43844 KB |
Output is correct |
22 |
Correct |
194 ms |
43888 KB |
Output is correct |
23 |
Correct |
253 ms |
43804 KB |
Output is correct |
24 |
Correct |
165 ms |
39540 KB |
Output is correct |
25 |
Correct |
168 ms |
39568 KB |
Output is correct |
26 |
Correct |
186 ms |
40196 KB |
Output is correct |
27 |
Correct |
221 ms |
40304 KB |
Output is correct |
28 |
Correct |
192 ms |
40340 KB |
Output is correct |
29 |
Correct |
209 ms |
41072 KB |
Output is correct |
30 |
Correct |
197 ms |
40924 KB |
Output is correct |
31 |
Correct |
200 ms |
41016 KB |
Output is correct |
32 |
Correct |
200 ms |
40900 KB |
Output is correct |
33 |
Correct |
210 ms |
40976 KB |
Output is correct |
34 |
Correct |
150 ms |
39164 KB |
Output is correct |
35 |
Correct |
163 ms |
39188 KB |
Output is correct |
36 |
Correct |
161 ms |
38904 KB |
Output is correct |
37 |
Correct |
170 ms |
39076 KB |
Output is correct |
38 |
Correct |
169 ms |
39308 KB |
Output is correct |
39 |
Correct |
174 ms |
40656 KB |
Output is correct |
40 |
Correct |
145 ms |
37692 KB |
Output is correct |
41 |
Correct |
171 ms |
38892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23756 KB |
Output is correct |
2 |
Correct |
12 ms |
23884 KB |
Output is correct |
3 |
Correct |
11 ms |
23808 KB |
Output is correct |
4 |
Correct |
12 ms |
23784 KB |
Output is correct |
5 |
Correct |
11 ms |
23800 KB |
Output is correct |
6 |
Correct |
13 ms |
23884 KB |
Output is correct |
7 |
Correct |
12 ms |
23812 KB |
Output is correct |
8 |
Correct |
11 ms |
23884 KB |
Output is correct |
9 |
Correct |
12 ms |
23808 KB |
Output is correct |
10 |
Correct |
11 ms |
23884 KB |
Output is correct |
11 |
Correct |
14 ms |
24072 KB |
Output is correct |
12 |
Correct |
18 ms |
24176 KB |
Output is correct |
13 |
Correct |
17 ms |
24268 KB |
Output is correct |
14 |
Correct |
19 ms |
24320 KB |
Output is correct |
15 |
Correct |
17 ms |
24400 KB |
Output is correct |
16 |
Correct |
16 ms |
24268 KB |
Output is correct |
17 |
Correct |
14 ms |
24204 KB |
Output is correct |
18 |
Correct |
14 ms |
24180 KB |
Output is correct |
19 |
Correct |
1424 ms |
107364 KB |
Output is correct |
20 |
Correct |
1415 ms |
107172 KB |
Output is correct |
21 |
Correct |
1379 ms |
107316 KB |
Output is correct |
22 |
Correct |
1421 ms |
106896 KB |
Output is correct |
23 |
Correct |
1154 ms |
91932 KB |
Output is correct |
24 |
Correct |
100 ms |
33156 KB |
Output is correct |
25 |
Correct |
91 ms |
32544 KB |
Output is correct |
26 |
Correct |
84 ms |
30848 KB |
Output is correct |
27 |
Correct |
83 ms |
31056 KB |
Output is correct |
28 |
Correct |
89 ms |
31108 KB |
Output is correct |
29 |
Correct |
73 ms |
30148 KB |
Output is correct |
30 |
Correct |
76 ms |
30112 KB |
Output is correct |
31 |
Correct |
80 ms |
30620 KB |
Output is correct |
32 |
Correct |
49 ms |
28736 KB |
Output is correct |
33 |
Correct |
88 ms |
30620 KB |
Output is correct |
34 |
Correct |
224 ms |
45072 KB |
Output is correct |
35 |
Correct |
271 ms |
45112 KB |
Output is correct |
36 |
Correct |
198 ms |
43844 KB |
Output is correct |
37 |
Correct |
194 ms |
43888 KB |
Output is correct |
38 |
Correct |
253 ms |
43804 KB |
Output is correct |
39 |
Correct |
165 ms |
39540 KB |
Output is correct |
40 |
Correct |
168 ms |
39568 KB |
Output is correct |
41 |
Correct |
186 ms |
40196 KB |
Output is correct |
42 |
Correct |
221 ms |
40304 KB |
Output is correct |
43 |
Correct |
192 ms |
40340 KB |
Output is correct |
44 |
Correct |
209 ms |
41072 KB |
Output is correct |
45 |
Correct |
197 ms |
40924 KB |
Output is correct |
46 |
Correct |
200 ms |
41016 KB |
Output is correct |
47 |
Correct |
200 ms |
40900 KB |
Output is correct |
48 |
Correct |
210 ms |
40976 KB |
Output is correct |
49 |
Correct |
150 ms |
39164 KB |
Output is correct |
50 |
Correct |
163 ms |
39188 KB |
Output is correct |
51 |
Correct |
161 ms |
38904 KB |
Output is correct |
52 |
Correct |
170 ms |
39076 KB |
Output is correct |
53 |
Correct |
169 ms |
39308 KB |
Output is correct |
54 |
Correct |
174 ms |
40656 KB |
Output is correct |
55 |
Correct |
145 ms |
37692 KB |
Output is correct |
56 |
Correct |
171 ms |
38892 KB |
Output is correct |
57 |
Correct |
1426 ms |
94376 KB |
Output is correct |
58 |
Correct |
1415 ms |
94164 KB |
Output is correct |
59 |
Correct |
1280 ms |
91576 KB |
Output is correct |
60 |
Correct |
1334 ms |
91548 KB |
Output is correct |
61 |
Correct |
1299 ms |
91520 KB |
Output is correct |
62 |
Correct |
1290 ms |
91548 KB |
Output is correct |
63 |
Correct |
859 ms |
71264 KB |
Output is correct |
64 |
Correct |
820 ms |
71188 KB |
Output is correct |
65 |
Correct |
1063 ms |
74824 KB |
Output is correct |
66 |
Correct |
1069 ms |
74856 KB |
Output is correct |
67 |
Correct |
1108 ms |
86652 KB |
Output is correct |
68 |
Correct |
1128 ms |
77844 KB |
Output is correct |
69 |
Correct |
1114 ms |
77832 KB |
Output is correct |
70 |
Correct |
1096 ms |
78376 KB |
Output is correct |
71 |
Correct |
1147 ms |
78304 KB |
Output is correct |
72 |
Correct |
1102 ms |
77168 KB |
Output is correct |
73 |
Correct |
781 ms |
70776 KB |
Output is correct |
74 |
Correct |
834 ms |
74092 KB |
Output is correct |
75 |
Correct |
782 ms |
74024 KB |
Output is correct |
76 |
Correct |
810 ms |
72828 KB |
Output is correct |
77 |
Correct |
786 ms |
72388 KB |
Output is correct |
78 |
Correct |
1038 ms |
81036 KB |
Output is correct |
79 |
Correct |
696 ms |
70724 KB |
Output is correct |
80 |
Correct |
986 ms |
76972 KB |
Output is correct |