#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
long long seg[4000005],red[1000005],ans[1000005];
vector<pair<pair<long long,long long>,long long>>q[1000005];
void update(long long l,long long r, long long now, long long pos,long long sum){
if(r<pos || l>pos)return ;
//cout<<sum<<" -0-0-"<<endl;
if(l==r){
seg[now]=max(seg[now],sum);
return ;
}
long long mid=(l+r)/2;
if(mid>=pos)update(l,mid,now*2+1,pos,sum);
else update(mid+1,r,now*2+2,pos,sum);
seg[now]=max(seg[now*2+1],seg[now*2+2]);
}
long long find_ans(long long l,long long r,long long L,long long R,long long now){
if(L>R)return 0;
//cout<<seg[now]<<" "<<now<<" P"<<l<<" "<<r<<endl;
if(l==L && r==R)return seg[now];
long long mid=(l+r)/2;
//cout<<l<<" "<<r<<endl;
return max(find_ans(l,mid,L,min(R,mid),now*2+1),find_ans(mid+1,r,max(L,mid+1),R,now*2+2));
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n,m;
cin>>n>>m;
for(int i=0;i<n;i++){cin>>red[i];}
for(int i=0;i<m;i++){
long long l,r,k;
cin>>l>>r>>k;
l--;r--;
q[l].push_back({{r,k},i});
}
stack<int>s;
for(int i=n-1;i>=0;i--){
while(s.empty()!=true && red[i]>=red[s.top()]){
if(red[i]!=red[s.top()]){
//cout<<i<<" ()()"<<red[s.top()]+red[i]<<endl;
update(0,n-1,0,s.top(),red[s.top()]+red[i]);
}
s.pop();
}
s.push(i);
for(int j=0;j<q[i].size();j++){
long long ha=find_ans(0,n-1,i,q[i][j].first.first,0);
//cout<<ha<<" - "<<q[i][j].first.first<<" "<<q[i][j].first.second<<endl;
if(ha<=q[i][j].first.second){
ans[q[i][j].second]=1;
}else{
ans[q[i][j].second]=0;
}
}
}
for(int i=0;i<m;i++){
cout<<ans[i]<<endl;
}
return 0;
}
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:55:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for(int j=0;j<q[i].size();j++){
| ~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
Output is correct |
2 |
Correct |
14 ms |
23712 KB |
Output is correct |
3 |
Correct |
13 ms |
23764 KB |
Output is correct |
4 |
Correct |
12 ms |
23764 KB |
Output is correct |
5 |
Correct |
12 ms |
23760 KB |
Output is correct |
6 |
Correct |
13 ms |
23764 KB |
Output is correct |
7 |
Correct |
13 ms |
23764 KB |
Output is correct |
8 |
Correct |
13 ms |
23860 KB |
Output is correct |
9 |
Correct |
14 ms |
23892 KB |
Output is correct |
10 |
Correct |
15 ms |
23812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
Output is correct |
2 |
Correct |
14 ms |
23712 KB |
Output is correct |
3 |
Correct |
13 ms |
23764 KB |
Output is correct |
4 |
Correct |
12 ms |
23764 KB |
Output is correct |
5 |
Correct |
12 ms |
23760 KB |
Output is correct |
6 |
Correct |
13 ms |
23764 KB |
Output is correct |
7 |
Correct |
13 ms |
23764 KB |
Output is correct |
8 |
Correct |
13 ms |
23860 KB |
Output is correct |
9 |
Correct |
14 ms |
23892 KB |
Output is correct |
10 |
Correct |
15 ms |
23812 KB |
Output is correct |
11 |
Correct |
14 ms |
23892 KB |
Output is correct |
12 |
Correct |
14 ms |
24020 KB |
Output is correct |
13 |
Correct |
15 ms |
24080 KB |
Output is correct |
14 |
Correct |
16 ms |
24180 KB |
Output is correct |
15 |
Correct |
16 ms |
24148 KB |
Output is correct |
16 |
Correct |
16 ms |
24148 KB |
Output is correct |
17 |
Correct |
15 ms |
24036 KB |
Output is correct |
18 |
Correct |
15 ms |
24012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1362 ms |
90504 KB |
Output is correct |
2 |
Correct |
1418 ms |
90352 KB |
Output is correct |
3 |
Correct |
1367 ms |
90388 KB |
Output is correct |
4 |
Correct |
1429 ms |
90316 KB |
Output is correct |
5 |
Correct |
1066 ms |
78096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
104 ms |
30844 KB |
Output is correct |
2 |
Correct |
95 ms |
31280 KB |
Output is correct |
3 |
Correct |
95 ms |
28876 KB |
Output is correct |
4 |
Correct |
98 ms |
28748 KB |
Output is correct |
5 |
Correct |
84 ms |
28748 KB |
Output is correct |
6 |
Correct |
71 ms |
29112 KB |
Output is correct |
7 |
Correct |
78 ms |
29108 KB |
Output is correct |
8 |
Correct |
88 ms |
28588 KB |
Output is correct |
9 |
Correct |
48 ms |
27696 KB |
Output is correct |
10 |
Correct |
70 ms |
28640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
Output is correct |
2 |
Correct |
14 ms |
23712 KB |
Output is correct |
3 |
Correct |
13 ms |
23764 KB |
Output is correct |
4 |
Correct |
12 ms |
23764 KB |
Output is correct |
5 |
Correct |
12 ms |
23760 KB |
Output is correct |
6 |
Correct |
13 ms |
23764 KB |
Output is correct |
7 |
Correct |
13 ms |
23764 KB |
Output is correct |
8 |
Correct |
13 ms |
23860 KB |
Output is correct |
9 |
Correct |
14 ms |
23892 KB |
Output is correct |
10 |
Correct |
15 ms |
23812 KB |
Output is correct |
11 |
Correct |
14 ms |
23892 KB |
Output is correct |
12 |
Correct |
14 ms |
24020 KB |
Output is correct |
13 |
Correct |
15 ms |
24080 KB |
Output is correct |
14 |
Correct |
16 ms |
24180 KB |
Output is correct |
15 |
Correct |
16 ms |
24148 KB |
Output is correct |
16 |
Correct |
16 ms |
24148 KB |
Output is correct |
17 |
Correct |
15 ms |
24036 KB |
Output is correct |
18 |
Correct |
15 ms |
24012 KB |
Output is correct |
19 |
Correct |
236 ms |
42212 KB |
Output is correct |
20 |
Correct |
239 ms |
44560 KB |
Output is correct |
21 |
Correct |
194 ms |
45376 KB |
Output is correct |
22 |
Correct |
202 ms |
45404 KB |
Output is correct |
23 |
Correct |
197 ms |
45408 KB |
Output is correct |
24 |
Correct |
170 ms |
41904 KB |
Output is correct |
25 |
Correct |
171 ms |
42032 KB |
Output is correct |
26 |
Correct |
198 ms |
41764 KB |
Output is correct |
27 |
Correct |
186 ms |
41772 KB |
Output is correct |
28 |
Correct |
241 ms |
41416 KB |
Output is correct |
29 |
Correct |
237 ms |
41180 KB |
Output is correct |
30 |
Correct |
215 ms |
41176 KB |
Output is correct |
31 |
Correct |
204 ms |
41104 KB |
Output is correct |
32 |
Correct |
203 ms |
41120 KB |
Output is correct |
33 |
Correct |
207 ms |
41108 KB |
Output is correct |
34 |
Correct |
155 ms |
40520 KB |
Output is correct |
35 |
Correct |
153 ms |
40444 KB |
Output is correct |
36 |
Correct |
166 ms |
40256 KB |
Output is correct |
37 |
Correct |
154 ms |
40496 KB |
Output is correct |
38 |
Correct |
153 ms |
40532 KB |
Output is correct |
39 |
Correct |
179 ms |
40568 KB |
Output is correct |
40 |
Correct |
136 ms |
37800 KB |
Output is correct |
41 |
Correct |
151 ms |
38036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
Output is correct |
2 |
Correct |
14 ms |
23712 KB |
Output is correct |
3 |
Correct |
13 ms |
23764 KB |
Output is correct |
4 |
Correct |
12 ms |
23764 KB |
Output is correct |
5 |
Correct |
12 ms |
23760 KB |
Output is correct |
6 |
Correct |
13 ms |
23764 KB |
Output is correct |
7 |
Correct |
13 ms |
23764 KB |
Output is correct |
8 |
Correct |
13 ms |
23860 KB |
Output is correct |
9 |
Correct |
14 ms |
23892 KB |
Output is correct |
10 |
Correct |
15 ms |
23812 KB |
Output is correct |
11 |
Correct |
14 ms |
23892 KB |
Output is correct |
12 |
Correct |
14 ms |
24020 KB |
Output is correct |
13 |
Correct |
15 ms |
24080 KB |
Output is correct |
14 |
Correct |
16 ms |
24180 KB |
Output is correct |
15 |
Correct |
16 ms |
24148 KB |
Output is correct |
16 |
Correct |
16 ms |
24148 KB |
Output is correct |
17 |
Correct |
15 ms |
24036 KB |
Output is correct |
18 |
Correct |
15 ms |
24012 KB |
Output is correct |
19 |
Correct |
1362 ms |
90504 KB |
Output is correct |
20 |
Correct |
1418 ms |
90352 KB |
Output is correct |
21 |
Correct |
1367 ms |
90388 KB |
Output is correct |
22 |
Correct |
1429 ms |
90316 KB |
Output is correct |
23 |
Correct |
1066 ms |
78096 KB |
Output is correct |
24 |
Correct |
104 ms |
30844 KB |
Output is correct |
25 |
Correct |
95 ms |
31280 KB |
Output is correct |
26 |
Correct |
95 ms |
28876 KB |
Output is correct |
27 |
Correct |
98 ms |
28748 KB |
Output is correct |
28 |
Correct |
84 ms |
28748 KB |
Output is correct |
29 |
Correct |
71 ms |
29112 KB |
Output is correct |
30 |
Correct |
78 ms |
29108 KB |
Output is correct |
31 |
Correct |
88 ms |
28588 KB |
Output is correct |
32 |
Correct |
48 ms |
27696 KB |
Output is correct |
33 |
Correct |
70 ms |
28640 KB |
Output is correct |
34 |
Correct |
236 ms |
42212 KB |
Output is correct |
35 |
Correct |
239 ms |
44560 KB |
Output is correct |
36 |
Correct |
194 ms |
45376 KB |
Output is correct |
37 |
Correct |
202 ms |
45404 KB |
Output is correct |
38 |
Correct |
197 ms |
45408 KB |
Output is correct |
39 |
Correct |
170 ms |
41904 KB |
Output is correct |
40 |
Correct |
171 ms |
42032 KB |
Output is correct |
41 |
Correct |
198 ms |
41764 KB |
Output is correct |
42 |
Correct |
186 ms |
41772 KB |
Output is correct |
43 |
Correct |
241 ms |
41416 KB |
Output is correct |
44 |
Correct |
237 ms |
41180 KB |
Output is correct |
45 |
Correct |
215 ms |
41176 KB |
Output is correct |
46 |
Correct |
204 ms |
41104 KB |
Output is correct |
47 |
Correct |
203 ms |
41120 KB |
Output is correct |
48 |
Correct |
207 ms |
41108 KB |
Output is correct |
49 |
Correct |
155 ms |
40520 KB |
Output is correct |
50 |
Correct |
153 ms |
40444 KB |
Output is correct |
51 |
Correct |
166 ms |
40256 KB |
Output is correct |
52 |
Correct |
154 ms |
40496 KB |
Output is correct |
53 |
Correct |
153 ms |
40532 KB |
Output is correct |
54 |
Correct |
179 ms |
40568 KB |
Output is correct |
55 |
Correct |
136 ms |
37800 KB |
Output is correct |
56 |
Correct |
151 ms |
38036 KB |
Output is correct |
57 |
Correct |
1361 ms |
100404 KB |
Output is correct |
58 |
Correct |
1470 ms |
100436 KB |
Output is correct |
59 |
Correct |
1313 ms |
102020 KB |
Output is correct |
60 |
Correct |
1403 ms |
102152 KB |
Output is correct |
61 |
Correct |
1334 ms |
107928 KB |
Output is correct |
62 |
Correct |
1317 ms |
102004 KB |
Output is correct |
63 |
Correct |
923 ms |
86000 KB |
Output is correct |
64 |
Correct |
974 ms |
85956 KB |
Output is correct |
65 |
Correct |
1232 ms |
90088 KB |
Output is correct |
66 |
Correct |
1261 ms |
90176 KB |
Output is correct |
67 |
Correct |
1315 ms |
89972 KB |
Output is correct |
68 |
Correct |
1153 ms |
88140 KB |
Output is correct |
69 |
Correct |
1199 ms |
88108 KB |
Output is correct |
70 |
Correct |
1113 ms |
88480 KB |
Output is correct |
71 |
Correct |
1105 ms |
88332 KB |
Output is correct |
72 |
Correct |
1148 ms |
88344 KB |
Output is correct |
73 |
Correct |
782 ms |
82220 KB |
Output is correct |
74 |
Correct |
859 ms |
82148 KB |
Output is correct |
75 |
Correct |
787 ms |
82060 KB |
Output is correct |
76 |
Correct |
757 ms |
81796 KB |
Output is correct |
77 |
Correct |
836 ms |
82116 KB |
Output is correct |
78 |
Correct |
1146 ms |
89244 KB |
Output is correct |
79 |
Correct |
694 ms |
88916 KB |
Output is correct |
80 |
Correct |
973 ms |
87204 KB |
Output is correct |