//upsolved after reading other's code
#include<bits/stdc++.h>
#define X s.top()
#define K 1<<20
using namespace std;
vector<tuple<int,int,int>>q[1<<20];
int n,a[1<<20],t[1<<20],m,r[1<<20];
void upd(int x,int v){
for(;x;x-=x&-x)
t[x]=max(t[x],v);
}
int qu(int x){
int v=0;
for(;x<=n;x+=x&-x)
v=max(t[x],v);
return v;
}
stack<int>s;
int main(){
cin.tie(0)->sync_with_stdio(0);
a[0]=2e9,s.push(0);
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=0,a,b,c;i<m;i++)
cin>>a>>b>>c,q[b].push_back({a,c,i});
for(int i=1;i<=n;i++){
while(a[X]<=a[i])
s.pop();
if(X) upd(X,a[X]+a[i]);
s.push(i);
for(auto[a,b,c]:q[i])
r[c]=qu(a)<=b;
}
for(int i=0;i<m;i++)
cout<<r[i]<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
30812 KB |
Output is correct |
2 |
Correct |
7 ms |
30812 KB |
Output is correct |
3 |
Correct |
9 ms |
30812 KB |
Output is correct |
4 |
Correct |
8 ms |
30900 KB |
Output is correct |
5 |
Correct |
7 ms |
30808 KB |
Output is correct |
6 |
Correct |
7 ms |
30940 KB |
Output is correct |
7 |
Correct |
8 ms |
31068 KB |
Output is correct |
8 |
Correct |
7 ms |
30920 KB |
Output is correct |
9 |
Correct |
7 ms |
31068 KB |
Output is correct |
10 |
Correct |
7 ms |
31068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
30812 KB |
Output is correct |
2 |
Correct |
7 ms |
30812 KB |
Output is correct |
3 |
Correct |
9 ms |
30812 KB |
Output is correct |
4 |
Correct |
8 ms |
30900 KB |
Output is correct |
5 |
Correct |
7 ms |
30808 KB |
Output is correct |
6 |
Correct |
7 ms |
30940 KB |
Output is correct |
7 |
Correct |
8 ms |
31068 KB |
Output is correct |
8 |
Correct |
7 ms |
30920 KB |
Output is correct |
9 |
Correct |
7 ms |
31068 KB |
Output is correct |
10 |
Correct |
7 ms |
31068 KB |
Output is correct |
11 |
Correct |
8 ms |
31320 KB |
Output is correct |
12 |
Correct |
9 ms |
31108 KB |
Output is correct |
13 |
Correct |
9 ms |
31064 KB |
Output is correct |
14 |
Correct |
9 ms |
31068 KB |
Output is correct |
15 |
Correct |
10 ms |
31064 KB |
Output is correct |
16 |
Correct |
9 ms |
31068 KB |
Output is correct |
17 |
Correct |
9 ms |
31068 KB |
Output is correct |
18 |
Correct |
11 ms |
31064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
654 ms |
61008 KB |
Output is correct |
2 |
Correct |
659 ms |
61008 KB |
Output is correct |
3 |
Correct |
669 ms |
60996 KB |
Output is correct |
4 |
Correct |
666 ms |
60896 KB |
Output is correct |
5 |
Correct |
677 ms |
58816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
37716 KB |
Output is correct |
2 |
Correct |
47 ms |
37640 KB |
Output is correct |
3 |
Correct |
46 ms |
37456 KB |
Output is correct |
4 |
Correct |
45 ms |
37440 KB |
Output is correct |
5 |
Correct |
46 ms |
37644 KB |
Output is correct |
6 |
Correct |
36 ms |
37204 KB |
Output is correct |
7 |
Correct |
36 ms |
37212 KB |
Output is correct |
8 |
Correct |
44 ms |
37388 KB |
Output is correct |
9 |
Correct |
30 ms |
34828 KB |
Output is correct |
10 |
Correct |
43 ms |
37388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
30812 KB |
Output is correct |
2 |
Correct |
7 ms |
30812 KB |
Output is correct |
3 |
Correct |
9 ms |
30812 KB |
Output is correct |
4 |
Correct |
8 ms |
30900 KB |
Output is correct |
5 |
Correct |
7 ms |
30808 KB |
Output is correct |
6 |
Correct |
7 ms |
30940 KB |
Output is correct |
7 |
Correct |
8 ms |
31068 KB |
Output is correct |
8 |
Correct |
7 ms |
30920 KB |
Output is correct |
9 |
Correct |
7 ms |
31068 KB |
Output is correct |
10 |
Correct |
7 ms |
31068 KB |
Output is correct |
11 |
Correct |
8 ms |
31320 KB |
Output is correct |
12 |
Correct |
9 ms |
31108 KB |
Output is correct |
13 |
Correct |
9 ms |
31064 KB |
Output is correct |
14 |
Correct |
9 ms |
31068 KB |
Output is correct |
15 |
Correct |
10 ms |
31064 KB |
Output is correct |
16 |
Correct |
9 ms |
31068 KB |
Output is correct |
17 |
Correct |
9 ms |
31068 KB |
Output is correct |
18 |
Correct |
11 ms |
31064 KB |
Output is correct |
19 |
Correct |
106 ms |
40532 KB |
Output is correct |
20 |
Correct |
103 ms |
40528 KB |
Output is correct |
21 |
Correct |
94 ms |
40016 KB |
Output is correct |
22 |
Correct |
94 ms |
40012 KB |
Output is correct |
23 |
Correct |
90 ms |
40016 KB |
Output is correct |
24 |
Correct |
81 ms |
39228 KB |
Output is correct |
25 |
Correct |
81 ms |
39248 KB |
Output is correct |
26 |
Correct |
90 ms |
39536 KB |
Output is correct |
27 |
Correct |
90 ms |
39500 KB |
Output is correct |
28 |
Correct |
88 ms |
39660 KB |
Output is correct |
29 |
Correct |
98 ms |
39760 KB |
Output is correct |
30 |
Correct |
97 ms |
39784 KB |
Output is correct |
31 |
Correct |
99 ms |
39864 KB |
Output is correct |
32 |
Correct |
97 ms |
39840 KB |
Output is correct |
33 |
Correct |
109 ms |
39852 KB |
Output is correct |
34 |
Correct |
77 ms |
38992 KB |
Output is correct |
35 |
Correct |
79 ms |
38944 KB |
Output is correct |
36 |
Correct |
95 ms |
38996 KB |
Output is correct |
37 |
Correct |
76 ms |
39068 KB |
Output is correct |
38 |
Correct |
79 ms |
38880 KB |
Output is correct |
39 |
Correct |
91 ms |
39692 KB |
Output is correct |
40 |
Correct |
79 ms |
39184 KB |
Output is correct |
41 |
Correct |
96 ms |
39388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
30812 KB |
Output is correct |
2 |
Correct |
7 ms |
30812 KB |
Output is correct |
3 |
Correct |
9 ms |
30812 KB |
Output is correct |
4 |
Correct |
8 ms |
30900 KB |
Output is correct |
5 |
Correct |
7 ms |
30808 KB |
Output is correct |
6 |
Correct |
7 ms |
30940 KB |
Output is correct |
7 |
Correct |
8 ms |
31068 KB |
Output is correct |
8 |
Correct |
7 ms |
30920 KB |
Output is correct |
9 |
Correct |
7 ms |
31068 KB |
Output is correct |
10 |
Correct |
7 ms |
31068 KB |
Output is correct |
11 |
Correct |
8 ms |
31320 KB |
Output is correct |
12 |
Correct |
9 ms |
31108 KB |
Output is correct |
13 |
Correct |
9 ms |
31064 KB |
Output is correct |
14 |
Correct |
9 ms |
31068 KB |
Output is correct |
15 |
Correct |
10 ms |
31064 KB |
Output is correct |
16 |
Correct |
9 ms |
31068 KB |
Output is correct |
17 |
Correct |
9 ms |
31068 KB |
Output is correct |
18 |
Correct |
11 ms |
31064 KB |
Output is correct |
19 |
Correct |
654 ms |
61008 KB |
Output is correct |
20 |
Correct |
659 ms |
61008 KB |
Output is correct |
21 |
Correct |
669 ms |
60996 KB |
Output is correct |
22 |
Correct |
666 ms |
60896 KB |
Output is correct |
23 |
Correct |
677 ms |
58816 KB |
Output is correct |
24 |
Correct |
49 ms |
37716 KB |
Output is correct |
25 |
Correct |
47 ms |
37640 KB |
Output is correct |
26 |
Correct |
46 ms |
37456 KB |
Output is correct |
27 |
Correct |
45 ms |
37440 KB |
Output is correct |
28 |
Correct |
46 ms |
37644 KB |
Output is correct |
29 |
Correct |
36 ms |
37204 KB |
Output is correct |
30 |
Correct |
36 ms |
37212 KB |
Output is correct |
31 |
Correct |
44 ms |
37388 KB |
Output is correct |
32 |
Correct |
30 ms |
34828 KB |
Output is correct |
33 |
Correct |
43 ms |
37388 KB |
Output is correct |
34 |
Correct |
106 ms |
40532 KB |
Output is correct |
35 |
Correct |
103 ms |
40528 KB |
Output is correct |
36 |
Correct |
94 ms |
40016 KB |
Output is correct |
37 |
Correct |
94 ms |
40012 KB |
Output is correct |
38 |
Correct |
90 ms |
40016 KB |
Output is correct |
39 |
Correct |
81 ms |
39228 KB |
Output is correct |
40 |
Correct |
81 ms |
39248 KB |
Output is correct |
41 |
Correct |
90 ms |
39536 KB |
Output is correct |
42 |
Correct |
90 ms |
39500 KB |
Output is correct |
43 |
Correct |
88 ms |
39660 KB |
Output is correct |
44 |
Correct |
98 ms |
39760 KB |
Output is correct |
45 |
Correct |
97 ms |
39784 KB |
Output is correct |
46 |
Correct |
99 ms |
39864 KB |
Output is correct |
47 |
Correct |
97 ms |
39840 KB |
Output is correct |
48 |
Correct |
109 ms |
39852 KB |
Output is correct |
49 |
Correct |
77 ms |
38992 KB |
Output is correct |
50 |
Correct |
79 ms |
38944 KB |
Output is correct |
51 |
Correct |
95 ms |
38996 KB |
Output is correct |
52 |
Correct |
76 ms |
39068 KB |
Output is correct |
53 |
Correct |
79 ms |
38880 KB |
Output is correct |
54 |
Correct |
91 ms |
39692 KB |
Output is correct |
55 |
Correct |
79 ms |
39184 KB |
Output is correct |
56 |
Correct |
96 ms |
39388 KB |
Output is correct |
57 |
Correct |
676 ms |
60496 KB |
Output is correct |
58 |
Correct |
644 ms |
60396 KB |
Output is correct |
59 |
Correct |
640 ms |
58920 KB |
Output is correct |
60 |
Correct |
613 ms |
59016 KB |
Output is correct |
61 |
Correct |
618 ms |
59264 KB |
Output is correct |
62 |
Correct |
601 ms |
59276 KB |
Output is correct |
63 |
Correct |
451 ms |
55632 KB |
Output is correct |
64 |
Correct |
394 ms |
55632 KB |
Output is correct |
65 |
Correct |
576 ms |
56748 KB |
Output is correct |
66 |
Correct |
553 ms |
56880 KB |
Output is correct |
67 |
Correct |
594 ms |
56908 KB |
Output is correct |
68 |
Correct |
621 ms |
58448 KB |
Output is correct |
69 |
Correct |
609 ms |
58308 KB |
Output is correct |
70 |
Correct |
624 ms |
58172 KB |
Output is correct |
71 |
Correct |
636 ms |
58200 KB |
Output is correct |
72 |
Correct |
601 ms |
58228 KB |
Output is correct |
73 |
Correct |
390 ms |
53072 KB |
Output is correct |
74 |
Correct |
355 ms |
53080 KB |
Output is correct |
75 |
Correct |
349 ms |
53280 KB |
Output is correct |
76 |
Correct |
347 ms |
53072 KB |
Output is correct |
77 |
Correct |
347 ms |
53072 KB |
Output is correct |
78 |
Correct |
604 ms |
57632 KB |
Output is correct |
79 |
Correct |
402 ms |
54516 KB |
Output is correct |
80 |
Correct |
524 ms |
57400 KB |
Output is correct |