#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define pii pair<int, int>
#define pipi pair<pii, pii>
int N = 1<<20;
vector<int> bin(2*N, 0);
vector<vector<int>> bmm(2*N);
int sol = 0;
int query(int curr, int l, int r, int a, int b, int mx)
{
if (l >= b || r <= a) return -1e9;
if (a <= l && r <= b)
{
sol = max(sol, bin[curr]);
auto u = lower_bound(bmm[curr].begin(), bmm[curr].end(), mx);
if (u!= bmm[curr].begin())
{
int last = *(--u);
sol = max(sol, mx+last);
}
return bmm[curr].back();
}
int m = (l+r)/2;
mx = max(mx, query(curr*2, l, m, a, b, mx));
mx = max(mx, query(curr*2+1, m, r, a, b, mx));
return mx;
}
int main()
{
int n, q;
cin >> n >> q;
for (int i = 0; i < n; i++)
{
int a;
cin >> a;
bmm[i+N].push_back(a);
}
for (int i = n; i < N; i++) bmm[i+N].push_back(1e9);
for (int i = N-1; i >0; i--)
{
bmm[i] = vector<int>(bmm[i*2]);
for (int ele:bmm[i*2+1]) bmm[i].push_back(ele);
sort(bmm[i].begin(), bmm[i].end());
bin[i] = max(bin[i*2], bin[i*2+1]);
int mx = bmm[i*2].back();
auto u = lower_bound(bmm[i*2+1].begin(), bmm[i*2+1].end(), mx);
if (u!=bmm[i*2+1].begin())
{
bin[i] = max(bin[i], mx+*(--u));
}
}
while(q--)
{
int l, r, mood;
cin >> l >> r >> mood;
l--;
sol=0;
query(1, 0, N, l, r, -1e9);
if (sol <= mood) cout << "1\n";
else cout << "0\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
285 ms |
194428 KB |
Output is correct |
2 |
Correct |
287 ms |
194456 KB |
Output is correct |
3 |
Correct |
286 ms |
194584 KB |
Output is correct |
4 |
Correct |
276 ms |
194564 KB |
Output is correct |
5 |
Correct |
275 ms |
194504 KB |
Output is correct |
6 |
Correct |
287 ms |
194504 KB |
Output is correct |
7 |
Correct |
295 ms |
194556 KB |
Output is correct |
8 |
Correct |
275 ms |
194592 KB |
Output is correct |
9 |
Correct |
341 ms |
194468 KB |
Output is correct |
10 |
Correct |
278 ms |
194704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
285 ms |
194428 KB |
Output is correct |
2 |
Correct |
287 ms |
194456 KB |
Output is correct |
3 |
Correct |
286 ms |
194584 KB |
Output is correct |
4 |
Correct |
276 ms |
194564 KB |
Output is correct |
5 |
Correct |
275 ms |
194504 KB |
Output is correct |
6 |
Correct |
287 ms |
194504 KB |
Output is correct |
7 |
Correct |
295 ms |
194556 KB |
Output is correct |
8 |
Correct |
275 ms |
194592 KB |
Output is correct |
9 |
Correct |
341 ms |
194468 KB |
Output is correct |
10 |
Correct |
278 ms |
194704 KB |
Output is correct |
11 |
Correct |
349 ms |
194632 KB |
Output is correct |
12 |
Correct |
292 ms |
194744 KB |
Output is correct |
13 |
Correct |
294 ms |
194760 KB |
Output is correct |
14 |
Correct |
288 ms |
194760 KB |
Output is correct |
15 |
Correct |
289 ms |
194756 KB |
Output is correct |
16 |
Correct |
291 ms |
194760 KB |
Output is correct |
17 |
Correct |
285 ms |
194640 KB |
Output is correct |
18 |
Correct |
290 ms |
194712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3082 ms |
218708 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
559 ms |
196632 KB |
Output is correct |
2 |
Correct |
578 ms |
196664 KB |
Output is correct |
3 |
Correct |
506 ms |
196804 KB |
Output is correct |
4 |
Correct |
512 ms |
196872 KB |
Output is correct |
5 |
Correct |
506 ms |
196804 KB |
Output is correct |
6 |
Correct |
484 ms |
196688 KB |
Output is correct |
7 |
Correct |
491 ms |
197064 KB |
Output is correct |
8 |
Correct |
547 ms |
196552 KB |
Output is correct |
9 |
Correct |
437 ms |
196704 KB |
Output is correct |
10 |
Correct |
496 ms |
196512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
285 ms |
194428 KB |
Output is correct |
2 |
Correct |
287 ms |
194456 KB |
Output is correct |
3 |
Correct |
286 ms |
194584 KB |
Output is correct |
4 |
Correct |
276 ms |
194564 KB |
Output is correct |
5 |
Correct |
275 ms |
194504 KB |
Output is correct |
6 |
Correct |
287 ms |
194504 KB |
Output is correct |
7 |
Correct |
295 ms |
194556 KB |
Output is correct |
8 |
Correct |
275 ms |
194592 KB |
Output is correct |
9 |
Correct |
341 ms |
194468 KB |
Output is correct |
10 |
Correct |
278 ms |
194704 KB |
Output is correct |
11 |
Correct |
349 ms |
194632 KB |
Output is correct |
12 |
Correct |
292 ms |
194744 KB |
Output is correct |
13 |
Correct |
294 ms |
194760 KB |
Output is correct |
14 |
Correct |
288 ms |
194760 KB |
Output is correct |
15 |
Correct |
289 ms |
194756 KB |
Output is correct |
16 |
Correct |
291 ms |
194760 KB |
Output is correct |
17 |
Correct |
285 ms |
194640 KB |
Output is correct |
18 |
Correct |
290 ms |
194712 KB |
Output is correct |
19 |
Correct |
965 ms |
201664 KB |
Output is correct |
20 |
Correct |
904 ms |
201664 KB |
Output is correct |
21 |
Correct |
823 ms |
201472 KB |
Output is correct |
22 |
Correct |
923 ms |
201436 KB |
Output is correct |
23 |
Correct |
846 ms |
201392 KB |
Output is correct |
24 |
Correct |
758 ms |
201800 KB |
Output is correct |
25 |
Correct |
791 ms |
201152 KB |
Output is correct |
26 |
Correct |
830 ms |
201536 KB |
Output is correct |
27 |
Correct |
830 ms |
201416 KB |
Output is correct |
28 |
Correct |
904 ms |
201392 KB |
Output is correct |
29 |
Correct |
835 ms |
201412 KB |
Output is correct |
30 |
Correct |
847 ms |
201644 KB |
Output is correct |
31 |
Correct |
835 ms |
201412 KB |
Output is correct |
32 |
Correct |
849 ms |
201672 KB |
Output is correct |
33 |
Correct |
875 ms |
201412 KB |
Output is correct |
34 |
Correct |
749 ms |
201180 KB |
Output is correct |
35 |
Correct |
735 ms |
201168 KB |
Output is correct |
36 |
Correct |
738 ms |
200896 KB |
Output is correct |
37 |
Correct |
767 ms |
200916 KB |
Output is correct |
38 |
Correct |
731 ms |
201156 KB |
Output is correct |
39 |
Correct |
862 ms |
200128 KB |
Output is correct |
40 |
Correct |
663 ms |
199360 KB |
Output is correct |
41 |
Correct |
759 ms |
199620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
285 ms |
194428 KB |
Output is correct |
2 |
Correct |
287 ms |
194456 KB |
Output is correct |
3 |
Correct |
286 ms |
194584 KB |
Output is correct |
4 |
Correct |
276 ms |
194564 KB |
Output is correct |
5 |
Correct |
275 ms |
194504 KB |
Output is correct |
6 |
Correct |
287 ms |
194504 KB |
Output is correct |
7 |
Correct |
295 ms |
194556 KB |
Output is correct |
8 |
Correct |
275 ms |
194592 KB |
Output is correct |
9 |
Correct |
341 ms |
194468 KB |
Output is correct |
10 |
Correct |
278 ms |
194704 KB |
Output is correct |
11 |
Correct |
349 ms |
194632 KB |
Output is correct |
12 |
Correct |
292 ms |
194744 KB |
Output is correct |
13 |
Correct |
294 ms |
194760 KB |
Output is correct |
14 |
Correct |
288 ms |
194760 KB |
Output is correct |
15 |
Correct |
289 ms |
194756 KB |
Output is correct |
16 |
Correct |
291 ms |
194760 KB |
Output is correct |
17 |
Correct |
285 ms |
194640 KB |
Output is correct |
18 |
Correct |
290 ms |
194712 KB |
Output is correct |
19 |
Execution timed out |
3082 ms |
218708 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |