#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(){
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 |
8 ms |
30812 KB |
Output is correct |
2 |
Correct |
7 ms |
30812 KB |
Output is correct |
3 |
Correct |
8 ms |
30808 KB |
Output is correct |
4 |
Correct |
7 ms |
30812 KB |
Output is correct |
5 |
Correct |
8 ms |
30812 KB |
Output is correct |
6 |
Correct |
8 ms |
30812 KB |
Output is correct |
7 |
Correct |
8 ms |
30812 KB |
Output is correct |
8 |
Correct |
7 ms |
30808 KB |
Output is correct |
9 |
Correct |
8 ms |
30812 KB |
Output is correct |
10 |
Correct |
7 ms |
30812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
30812 KB |
Output is correct |
2 |
Correct |
7 ms |
30812 KB |
Output is correct |
3 |
Correct |
8 ms |
30808 KB |
Output is correct |
4 |
Correct |
7 ms |
30812 KB |
Output is correct |
5 |
Correct |
8 ms |
30812 KB |
Output is correct |
6 |
Correct |
8 ms |
30812 KB |
Output is correct |
7 |
Correct |
8 ms |
30812 KB |
Output is correct |
8 |
Correct |
7 ms |
30808 KB |
Output is correct |
9 |
Correct |
8 ms |
30812 KB |
Output is correct |
10 |
Correct |
7 ms |
30812 KB |
Output is correct |
11 |
Correct |
10 ms |
31064 KB |
Output is correct |
12 |
Correct |
11 ms |
31064 KB |
Output is correct |
13 |
Correct |
11 ms |
31068 KB |
Output is correct |
14 |
Correct |
14 ms |
31036 KB |
Output is correct |
15 |
Correct |
16 ms |
31068 KB |
Output is correct |
16 |
Correct |
11 ms |
31072 KB |
Output is correct |
17 |
Correct |
11 ms |
31068 KB |
Output is correct |
18 |
Correct |
10 ms |
31064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1603 ms |
60856 KB |
Output is correct |
2 |
Correct |
1570 ms |
61132 KB |
Output is correct |
3 |
Correct |
1555 ms |
60864 KB |
Output is correct |
4 |
Correct |
1602 ms |
61204 KB |
Output is correct |
5 |
Correct |
1610 ms |
58808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
104 ms |
37764 KB |
Output is correct |
2 |
Correct |
106 ms |
37780 KB |
Output is correct |
3 |
Correct |
109 ms |
37480 KB |
Output is correct |
4 |
Correct |
109 ms |
37532 KB |
Output is correct |
5 |
Correct |
102 ms |
37456 KB |
Output is correct |
6 |
Correct |
90 ms |
36992 KB |
Output is correct |
7 |
Correct |
92 ms |
37064 KB |
Output is correct |
8 |
Correct |
93 ms |
37384 KB |
Output is correct |
9 |
Correct |
70 ms |
34832 KB |
Output is correct |
10 |
Correct |
96 ms |
37472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
30812 KB |
Output is correct |
2 |
Correct |
7 ms |
30812 KB |
Output is correct |
3 |
Correct |
8 ms |
30808 KB |
Output is correct |
4 |
Correct |
7 ms |
30812 KB |
Output is correct |
5 |
Correct |
8 ms |
30812 KB |
Output is correct |
6 |
Correct |
8 ms |
30812 KB |
Output is correct |
7 |
Correct |
8 ms |
30812 KB |
Output is correct |
8 |
Correct |
7 ms |
30808 KB |
Output is correct |
9 |
Correct |
8 ms |
30812 KB |
Output is correct |
10 |
Correct |
7 ms |
30812 KB |
Output is correct |
11 |
Correct |
10 ms |
31064 KB |
Output is correct |
12 |
Correct |
11 ms |
31064 KB |
Output is correct |
13 |
Correct |
11 ms |
31068 KB |
Output is correct |
14 |
Correct |
14 ms |
31036 KB |
Output is correct |
15 |
Correct |
16 ms |
31068 KB |
Output is correct |
16 |
Correct |
11 ms |
31072 KB |
Output is correct |
17 |
Correct |
11 ms |
31068 KB |
Output is correct |
18 |
Correct |
10 ms |
31064 KB |
Output is correct |
19 |
Correct |
299 ms |
40500 KB |
Output is correct |
20 |
Correct |
274 ms |
40344 KB |
Output is correct |
21 |
Correct |
267 ms |
40288 KB |
Output is correct |
22 |
Correct |
259 ms |
40020 KB |
Output is correct |
23 |
Correct |
257 ms |
39976 KB |
Output is correct |
24 |
Correct |
245 ms |
39204 KB |
Output is correct |
25 |
Correct |
263 ms |
45648 KB |
Output is correct |
26 |
Correct |
281 ms |
46044 KB |
Output is correct |
27 |
Correct |
263 ms |
45908 KB |
Output is correct |
28 |
Correct |
274 ms |
46076 KB |
Output is correct |
29 |
Correct |
268 ms |
46420 KB |
Output is correct |
30 |
Correct |
293 ms |
46292 KB |
Output is correct |
31 |
Correct |
271 ms |
46488 KB |
Output is correct |
32 |
Correct |
303 ms |
46416 KB |
Output is correct |
33 |
Correct |
304 ms |
46348 KB |
Output is correct |
34 |
Correct |
260 ms |
45080 KB |
Output is correct |
35 |
Correct |
255 ms |
45160 KB |
Output is correct |
36 |
Correct |
255 ms |
45080 KB |
Output is correct |
37 |
Correct |
240 ms |
45208 KB |
Output is correct |
38 |
Correct |
257 ms |
45140 KB |
Output is correct |
39 |
Correct |
238 ms |
44848 KB |
Output is correct |
40 |
Correct |
218 ms |
43728 KB |
Output is correct |
41 |
Correct |
234 ms |
44292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
30812 KB |
Output is correct |
2 |
Correct |
7 ms |
30812 KB |
Output is correct |
3 |
Correct |
8 ms |
30808 KB |
Output is correct |
4 |
Correct |
7 ms |
30812 KB |
Output is correct |
5 |
Correct |
8 ms |
30812 KB |
Output is correct |
6 |
Correct |
8 ms |
30812 KB |
Output is correct |
7 |
Correct |
8 ms |
30812 KB |
Output is correct |
8 |
Correct |
7 ms |
30808 KB |
Output is correct |
9 |
Correct |
8 ms |
30812 KB |
Output is correct |
10 |
Correct |
7 ms |
30812 KB |
Output is correct |
11 |
Correct |
10 ms |
31064 KB |
Output is correct |
12 |
Correct |
11 ms |
31064 KB |
Output is correct |
13 |
Correct |
11 ms |
31068 KB |
Output is correct |
14 |
Correct |
14 ms |
31036 KB |
Output is correct |
15 |
Correct |
16 ms |
31068 KB |
Output is correct |
16 |
Correct |
11 ms |
31072 KB |
Output is correct |
17 |
Correct |
11 ms |
31068 KB |
Output is correct |
18 |
Correct |
10 ms |
31064 KB |
Output is correct |
19 |
Correct |
1603 ms |
60856 KB |
Output is correct |
20 |
Correct |
1570 ms |
61132 KB |
Output is correct |
21 |
Correct |
1555 ms |
60864 KB |
Output is correct |
22 |
Correct |
1602 ms |
61204 KB |
Output is correct |
23 |
Correct |
1610 ms |
58808 KB |
Output is correct |
24 |
Correct |
104 ms |
37764 KB |
Output is correct |
25 |
Correct |
106 ms |
37780 KB |
Output is correct |
26 |
Correct |
109 ms |
37480 KB |
Output is correct |
27 |
Correct |
109 ms |
37532 KB |
Output is correct |
28 |
Correct |
102 ms |
37456 KB |
Output is correct |
29 |
Correct |
90 ms |
36992 KB |
Output is correct |
30 |
Correct |
92 ms |
37064 KB |
Output is correct |
31 |
Correct |
93 ms |
37384 KB |
Output is correct |
32 |
Correct |
70 ms |
34832 KB |
Output is correct |
33 |
Correct |
96 ms |
37472 KB |
Output is correct |
34 |
Correct |
299 ms |
40500 KB |
Output is correct |
35 |
Correct |
274 ms |
40344 KB |
Output is correct |
36 |
Correct |
267 ms |
40288 KB |
Output is correct |
37 |
Correct |
259 ms |
40020 KB |
Output is correct |
38 |
Correct |
257 ms |
39976 KB |
Output is correct |
39 |
Correct |
245 ms |
39204 KB |
Output is correct |
40 |
Correct |
263 ms |
45648 KB |
Output is correct |
41 |
Correct |
281 ms |
46044 KB |
Output is correct |
42 |
Correct |
263 ms |
45908 KB |
Output is correct |
43 |
Correct |
274 ms |
46076 KB |
Output is correct |
44 |
Correct |
268 ms |
46420 KB |
Output is correct |
45 |
Correct |
293 ms |
46292 KB |
Output is correct |
46 |
Correct |
271 ms |
46488 KB |
Output is correct |
47 |
Correct |
303 ms |
46416 KB |
Output is correct |
48 |
Correct |
304 ms |
46348 KB |
Output is correct |
49 |
Correct |
260 ms |
45080 KB |
Output is correct |
50 |
Correct |
255 ms |
45160 KB |
Output is correct |
51 |
Correct |
255 ms |
45080 KB |
Output is correct |
52 |
Correct |
240 ms |
45208 KB |
Output is correct |
53 |
Correct |
257 ms |
45140 KB |
Output is correct |
54 |
Correct |
238 ms |
44848 KB |
Output is correct |
55 |
Correct |
218 ms |
43728 KB |
Output is correct |
56 |
Correct |
234 ms |
44292 KB |
Output is correct |
57 |
Correct |
1665 ms |
93876 KB |
Output is correct |
58 |
Correct |
1633 ms |
94180 KB |
Output is correct |
59 |
Correct |
1502 ms |
92648 KB |
Output is correct |
60 |
Correct |
1642 ms |
92428 KB |
Output is correct |
61 |
Correct |
1466 ms |
92300 KB |
Output is correct |
62 |
Correct |
1623 ms |
92296 KB |
Output is correct |
63 |
Correct |
1272 ms |
87412 KB |
Output is correct |
64 |
Correct |
1243 ms |
87252 KB |
Output is correct |
65 |
Correct |
1530 ms |
90196 KB |
Output is correct |
66 |
Correct |
1449 ms |
90252 KB |
Output is correct |
67 |
Correct |
1483 ms |
90220 KB |
Output is correct |
68 |
Correct |
1631 ms |
91984 KB |
Output is correct |
69 |
Correct |
1597 ms |
91848 KB |
Output is correct |
70 |
Correct |
1651 ms |
91744 KB |
Output is correct |
71 |
Correct |
1617 ms |
91752 KB |
Output is correct |
72 |
Correct |
1706 ms |
91536 KB |
Output is correct |
73 |
Correct |
1214 ms |
83096 KB |
Output is correct |
74 |
Correct |
1219 ms |
84308 KB |
Output is correct |
75 |
Correct |
1233 ms |
83112 KB |
Output is correct |
76 |
Correct |
1274 ms |
83412 KB |
Output is correct |
77 |
Correct |
1225 ms |
83052 KB |
Output is correct |
78 |
Correct |
1393 ms |
84816 KB |
Output is correct |
79 |
Correct |
1151 ms |
77040 KB |
Output is correct |
80 |
Correct |
1285 ms |
83196 KB |
Output is correct |