#include <bits/stdc++.h>
using namespace std;
int n,q;
int a[1000005];
int tree[1000005];
void upd(int id,int val) {
while(id>0) {
tree[id]=max(tree[id],val);
id-=(id&(-id));
}
}
int get(int id) {
int maxx=-2e9;
while(id<=n) {
maxx=max(maxx,tree[id]);
id+=(id&(-id));
}
return maxx;
}
struct que {
int l,r,k,id;
} qu[1000005];
bool cmp(que a,que b) {
return a.r<b.r;
}
int ans[1000005];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>q;
for(int i=1; i<=n; i++)cin>>a[i];
for(int i=1; i<=q; i++) {
int l,r,k;
cin>>l>>r>>k;
qu[i]= {l,r,k,i};
}
for(int i=1;i<=n;i++)tree[i]=-2e9;
sort(qu+1,qu+q+1,cmp);
int dd=0;
stack<int>st;
for(int i=1; i<=q; i++) {
while(dd+1<=qu[i].r) {
dd++;
while(st.size()&&a[st.top()]<=a[dd])st.pop();
if(st.size()>0){upd(st.top(),a[st.top()]+a[dd]);}
st.push(dd);
}
if(get(qu[i].l)>qu[i].k)ans[qu[i].id]=0;
else ans[qu[i].id]=1;
}
for(int i=1; i<=q; i++)cout<<ans[i]<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
3 ms |
596 KB |
Output is correct |
15 |
Correct |
3 ms |
556 KB |
Output is correct |
16 |
Correct |
3 ms |
596 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
3 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
495 ms |
29836 KB |
Output is correct |
2 |
Correct |
509 ms |
30084 KB |
Output is correct |
3 |
Correct |
513 ms |
30008 KB |
Output is correct |
4 |
Correct |
521 ms |
30012 KB |
Output is correct |
5 |
Correct |
507 ms |
30016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
3616 KB |
Output is correct |
2 |
Correct |
42 ms |
5176 KB |
Output is correct |
3 |
Correct |
39 ms |
5192 KB |
Output is correct |
4 |
Correct |
40 ms |
5180 KB |
Output is correct |
5 |
Correct |
39 ms |
5196 KB |
Output is correct |
6 |
Correct |
52 ms |
5028 KB |
Output is correct |
7 |
Correct |
45 ms |
4992 KB |
Output is correct |
8 |
Correct |
37 ms |
4848 KB |
Output is correct |
9 |
Correct |
28 ms |
3748 KB |
Output is correct |
10 |
Correct |
37 ms |
4908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
3 ms |
596 KB |
Output is correct |
15 |
Correct |
3 ms |
556 KB |
Output is correct |
16 |
Correct |
3 ms |
596 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
3 ms |
468 KB |
Output is correct |
19 |
Correct |
99 ms |
12752 KB |
Output is correct |
20 |
Correct |
108 ms |
12856 KB |
Output is correct |
21 |
Correct |
96 ms |
12532 KB |
Output is correct |
22 |
Correct |
95 ms |
12616 KB |
Output is correct |
23 |
Correct |
96 ms |
12572 KB |
Output is correct |
24 |
Correct |
91 ms |
12496 KB |
Output is correct |
25 |
Correct |
89 ms |
12432 KB |
Output is correct |
26 |
Correct |
91 ms |
12624 KB |
Output is correct |
27 |
Correct |
92 ms |
12688 KB |
Output is correct |
28 |
Correct |
104 ms |
12620 KB |
Output is correct |
29 |
Correct |
94 ms |
12756 KB |
Output is correct |
30 |
Correct |
95 ms |
12748 KB |
Output is correct |
31 |
Correct |
94 ms |
12792 KB |
Output is correct |
32 |
Correct |
97 ms |
12792 KB |
Output is correct |
33 |
Correct |
95 ms |
12804 KB |
Output is correct |
34 |
Correct |
88 ms |
12368 KB |
Output is correct |
35 |
Correct |
87 ms |
12308 KB |
Output is correct |
36 |
Correct |
92 ms |
12184 KB |
Output is correct |
37 |
Correct |
86 ms |
12144 KB |
Output is correct |
38 |
Correct |
97 ms |
12520 KB |
Output is correct |
39 |
Correct |
86 ms |
11292 KB |
Output is correct |
40 |
Correct |
73 ms |
10120 KB |
Output is correct |
41 |
Correct |
81 ms |
10912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
3 ms |
596 KB |
Output is correct |
15 |
Correct |
3 ms |
556 KB |
Output is correct |
16 |
Correct |
3 ms |
596 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
3 ms |
468 KB |
Output is correct |
19 |
Correct |
495 ms |
29836 KB |
Output is correct |
20 |
Correct |
509 ms |
30084 KB |
Output is correct |
21 |
Correct |
513 ms |
30008 KB |
Output is correct |
22 |
Correct |
521 ms |
30012 KB |
Output is correct |
23 |
Correct |
507 ms |
30016 KB |
Output is correct |
24 |
Correct |
56 ms |
3616 KB |
Output is correct |
25 |
Correct |
42 ms |
5176 KB |
Output is correct |
26 |
Correct |
39 ms |
5192 KB |
Output is correct |
27 |
Correct |
40 ms |
5180 KB |
Output is correct |
28 |
Correct |
39 ms |
5196 KB |
Output is correct |
29 |
Correct |
52 ms |
5028 KB |
Output is correct |
30 |
Correct |
45 ms |
4992 KB |
Output is correct |
31 |
Correct |
37 ms |
4848 KB |
Output is correct |
32 |
Correct |
28 ms |
3748 KB |
Output is correct |
33 |
Correct |
37 ms |
4908 KB |
Output is correct |
34 |
Correct |
99 ms |
12752 KB |
Output is correct |
35 |
Correct |
108 ms |
12856 KB |
Output is correct |
36 |
Correct |
96 ms |
12532 KB |
Output is correct |
37 |
Correct |
95 ms |
12616 KB |
Output is correct |
38 |
Correct |
96 ms |
12572 KB |
Output is correct |
39 |
Correct |
91 ms |
12496 KB |
Output is correct |
40 |
Correct |
89 ms |
12432 KB |
Output is correct |
41 |
Correct |
91 ms |
12624 KB |
Output is correct |
42 |
Correct |
92 ms |
12688 KB |
Output is correct |
43 |
Correct |
104 ms |
12620 KB |
Output is correct |
44 |
Correct |
94 ms |
12756 KB |
Output is correct |
45 |
Correct |
95 ms |
12748 KB |
Output is correct |
46 |
Correct |
94 ms |
12792 KB |
Output is correct |
47 |
Correct |
97 ms |
12792 KB |
Output is correct |
48 |
Correct |
95 ms |
12804 KB |
Output is correct |
49 |
Correct |
88 ms |
12368 KB |
Output is correct |
50 |
Correct |
87 ms |
12308 KB |
Output is correct |
51 |
Correct |
92 ms |
12184 KB |
Output is correct |
52 |
Correct |
86 ms |
12144 KB |
Output is correct |
53 |
Correct |
97 ms |
12520 KB |
Output is correct |
54 |
Correct |
86 ms |
11292 KB |
Output is correct |
55 |
Correct |
73 ms |
10120 KB |
Output is correct |
56 |
Correct |
81 ms |
10912 KB |
Output is correct |
57 |
Correct |
523 ms |
34740 KB |
Output is correct |
58 |
Correct |
537 ms |
34688 KB |
Output is correct |
59 |
Correct |
495 ms |
34620 KB |
Output is correct |
60 |
Correct |
494 ms |
34616 KB |
Output is correct |
61 |
Correct |
489 ms |
34744 KB |
Output is correct |
62 |
Correct |
512 ms |
34600 KB |
Output is correct |
63 |
Correct |
428 ms |
34284 KB |
Output is correct |
64 |
Correct |
435 ms |
34344 KB |
Output is correct |
65 |
Correct |
465 ms |
34660 KB |
Output is correct |
66 |
Correct |
466 ms |
34652 KB |
Output is correct |
67 |
Correct |
466 ms |
34744 KB |
Output is correct |
68 |
Correct |
481 ms |
34792 KB |
Output is correct |
69 |
Correct |
483 ms |
34716 KB |
Output is correct |
70 |
Correct |
470 ms |
34692 KB |
Output is correct |
71 |
Correct |
465 ms |
34704 KB |
Output is correct |
72 |
Correct |
473 ms |
34680 KB |
Output is correct |
73 |
Correct |
421 ms |
34344 KB |
Output is correct |
74 |
Correct |
426 ms |
34320 KB |
Output is correct |
75 |
Correct |
419 ms |
34268 KB |
Output is correct |
76 |
Correct |
426 ms |
34340 KB |
Output is correct |
77 |
Correct |
425 ms |
34300 KB |
Output is correct |
78 |
Correct |
462 ms |
34028 KB |
Output is correct |
79 |
Correct |
368 ms |
30236 KB |
Output is correct |
80 |
Correct |
430 ms |
33996 KB |
Output is correct |