#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,i,j,ii,jj,zx,xc,tes,t,f[200009],za,seg2[800009],mx,l,r,z,K;
vector <int> seg[800009];
void bld(int q, int w, int rr){
if(q==w) return;
bld(q,(q+w)/2,rr*2);
bld((q+w)/2+1,w,rr*2+1);
int h=0,hh=0;
for(h=0; h<seg[rr*2+1].size(); h++){
if(seg[rr*2+1][h]>=seg[rr*2][seg[rr*2].size()-1]) break;
seg2[rr]=seg[rr*2][seg[rr*2].size()-1]+seg[rr*2+1][h];
}
seg2[rr]=max(seg2[rr],seg2[rr*2]);
seg2[rr]=max(seg2[rr],seg2[rr*2+1]);
h=0;hh=0;
//cout<<q<<" "<<w<<" "<<seg[rr*2].size()<<" "<<seg[rr*2+1].size()<<"\n";
while(h<seg[rr*2].size()||hh<seg[rr*2+1].size()){
if(h>=seg[rr*2].size()){
seg[rr].push_back(seg[rr*2+1][hh]);hh++;
continue;
}
if(hh>=seg[rr*2+1].size()){
seg[rr].push_back(seg[rr*2][h]);h++;
continue;
}
if(seg[rr*2][h]<=seg[rr*2+1][hh]){
seg[rr].push_back(seg[rr*2][h]);h++;
continue;
}else{
seg[rr].push_back(seg[rr*2+1][hh]);hh++;
continue;
}
}
}
void read(int q, int w, int rr){
if(q>r||w<l) return;
if(q>=l&&w<=r){
z=max(z,seg2[rr]);
c=lower_bound(seg[rr].begin(),seg[rr].end(),mx)-seg[rr].begin();
if(c==0){
mx=max(mx,seg[rr][seg[rr].size()-1]);
return;
}
c--;
z=max(z,mx+seg[rr][c]);
mx=max(mx,seg[rr][seg[rr].size()-1]);
return;
}
read(q,(q+w)/2,rr*2);
read((q+w)/2+1,w,rr*2+1);
}
int main(){
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>a>>tes;
for(i=1; i<=a; i++){
cin>>f[i];
}
za=1;
while(za<a) za*=2;
for(i=1; i<=a; i++){
seg[i+za-1].push_back(f[i]);
}
for(i=a+1; i<=za; i++){
seg[i+za-1].push_back(1000000000);
}
bld(1,za,1);
//exit(0);
for(t=1; t<=tes; t++){
cin>>l>>r>>K;z=0;mx=0;
read(1,za,1);
if(z<=K){
cout<<"1\n";
}else{
cout<<"0\n";
}
}
return 0;
}
Compilation message
sortbooks.cpp: In function 'void bld(int, int, int)':
sortbooks.cpp:10:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
10 | for(h=0; h<seg[rr*2+1].size(); h++){
| ~^~~~~~~~~~~~~~~~~~~
sortbooks.cpp:18:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | while(h<seg[rr*2].size()||hh<seg[rr*2+1].size()){
| ~^~~~~~~~~~~~~~~~~
sortbooks.cpp:18:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | while(h<seg[rr*2].size()||hh<seg[rr*2+1].size()){
| ~~^~~~~~~~~~~~~~~~~~~
sortbooks.cpp:19:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | if(h>=seg[rr*2].size()){
| ~^~~~~~~~~~~~~~~~~~
sortbooks.cpp:23:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | if(hh>=seg[rr*2+1].size()){
| ~~^~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
19020 KB |
Output is correct |
2 |
Correct |
9 ms |
19020 KB |
Output is correct |
3 |
Correct |
9 ms |
19112 KB |
Output is correct |
4 |
Correct |
9 ms |
19100 KB |
Output is correct |
5 |
Correct |
12 ms |
19116 KB |
Output is correct |
6 |
Correct |
10 ms |
19112 KB |
Output is correct |
7 |
Correct |
10 ms |
19140 KB |
Output is correct |
8 |
Correct |
10 ms |
19132 KB |
Output is correct |
9 |
Correct |
9 ms |
19152 KB |
Output is correct |
10 |
Correct |
9 ms |
19152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
19020 KB |
Output is correct |
2 |
Correct |
9 ms |
19020 KB |
Output is correct |
3 |
Correct |
9 ms |
19112 KB |
Output is correct |
4 |
Correct |
9 ms |
19100 KB |
Output is correct |
5 |
Correct |
12 ms |
19116 KB |
Output is correct |
6 |
Correct |
10 ms |
19112 KB |
Output is correct |
7 |
Correct |
10 ms |
19140 KB |
Output is correct |
8 |
Correct |
10 ms |
19132 KB |
Output is correct |
9 |
Correct |
9 ms |
19152 KB |
Output is correct |
10 |
Correct |
9 ms |
19152 KB |
Output is correct |
11 |
Correct |
11 ms |
19376 KB |
Output is correct |
12 |
Correct |
13 ms |
20104 KB |
Output is correct |
13 |
Correct |
14 ms |
19996 KB |
Output is correct |
14 |
Correct |
15 ms |
20132 KB |
Output is correct |
15 |
Correct |
15 ms |
20172 KB |
Output is correct |
16 |
Correct |
15 ms |
20140 KB |
Output is correct |
17 |
Correct |
12 ms |
19628 KB |
Output is correct |
18 |
Correct |
14 ms |
20044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
41 ms |
40268 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
202 ms |
36276 KB |
Output is correct |
2 |
Correct |
171 ms |
37712 KB |
Output is correct |
3 |
Correct |
155 ms |
37776 KB |
Output is correct |
4 |
Correct |
162 ms |
37832 KB |
Output is correct |
5 |
Correct |
156 ms |
37820 KB |
Output is correct |
6 |
Correct |
121 ms |
37692 KB |
Output is correct |
7 |
Correct |
121 ms |
37660 KB |
Output is correct |
8 |
Correct |
137 ms |
37436 KB |
Output is correct |
9 |
Correct |
41 ms |
20548 KB |
Output is correct |
10 |
Correct |
164 ms |
37524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
19020 KB |
Output is correct |
2 |
Correct |
9 ms |
19020 KB |
Output is correct |
3 |
Correct |
9 ms |
19112 KB |
Output is correct |
4 |
Correct |
9 ms |
19100 KB |
Output is correct |
5 |
Correct |
12 ms |
19116 KB |
Output is correct |
6 |
Correct |
10 ms |
19112 KB |
Output is correct |
7 |
Correct |
10 ms |
19140 KB |
Output is correct |
8 |
Correct |
10 ms |
19132 KB |
Output is correct |
9 |
Correct |
9 ms |
19152 KB |
Output is correct |
10 |
Correct |
9 ms |
19152 KB |
Output is correct |
11 |
Correct |
11 ms |
19376 KB |
Output is correct |
12 |
Correct |
13 ms |
20104 KB |
Output is correct |
13 |
Correct |
14 ms |
19996 KB |
Output is correct |
14 |
Correct |
15 ms |
20132 KB |
Output is correct |
15 |
Correct |
15 ms |
20172 KB |
Output is correct |
16 |
Correct |
15 ms |
20140 KB |
Output is correct |
17 |
Correct |
12 ms |
19628 KB |
Output is correct |
18 |
Correct |
14 ms |
20044 KB |
Output is correct |
19 |
Correct |
444 ms |
60296 KB |
Output is correct |
20 |
Correct |
430 ms |
60188 KB |
Output is correct |
21 |
Correct |
344 ms |
60180 KB |
Output is correct |
22 |
Correct |
336 ms |
59960 KB |
Output is correct |
23 |
Correct |
361 ms |
60008 KB |
Output is correct |
24 |
Correct |
314 ms |
60116 KB |
Output is correct |
25 |
Correct |
293 ms |
59964 KB |
Output is correct |
26 |
Correct |
362 ms |
60140 KB |
Output is correct |
27 |
Correct |
374 ms |
60092 KB |
Output is correct |
28 |
Correct |
375 ms |
60184 KB |
Output is correct |
29 |
Correct |
365 ms |
60224 KB |
Output is correct |
30 |
Correct |
372 ms |
60288 KB |
Output is correct |
31 |
Correct |
377 ms |
60216 KB |
Output is correct |
32 |
Correct |
387 ms |
60296 KB |
Output is correct |
33 |
Correct |
370 ms |
60152 KB |
Output is correct |
34 |
Correct |
262 ms |
59832 KB |
Output is correct |
35 |
Correct |
256 ms |
59864 KB |
Output is correct |
36 |
Correct |
258 ms |
59604 KB |
Output is correct |
37 |
Correct |
252 ms |
59544 KB |
Output is correct |
38 |
Correct |
270 ms |
59916 KB |
Output is correct |
39 |
Correct |
337 ms |
58712 KB |
Output is correct |
40 |
Correct |
213 ms |
40644 KB |
Output is correct |
41 |
Correct |
329 ms |
58312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
19020 KB |
Output is correct |
2 |
Correct |
9 ms |
19020 KB |
Output is correct |
3 |
Correct |
9 ms |
19112 KB |
Output is correct |
4 |
Correct |
9 ms |
19100 KB |
Output is correct |
5 |
Correct |
12 ms |
19116 KB |
Output is correct |
6 |
Correct |
10 ms |
19112 KB |
Output is correct |
7 |
Correct |
10 ms |
19140 KB |
Output is correct |
8 |
Correct |
10 ms |
19132 KB |
Output is correct |
9 |
Correct |
9 ms |
19152 KB |
Output is correct |
10 |
Correct |
9 ms |
19152 KB |
Output is correct |
11 |
Correct |
11 ms |
19376 KB |
Output is correct |
12 |
Correct |
13 ms |
20104 KB |
Output is correct |
13 |
Correct |
14 ms |
19996 KB |
Output is correct |
14 |
Correct |
15 ms |
20132 KB |
Output is correct |
15 |
Correct |
15 ms |
20172 KB |
Output is correct |
16 |
Correct |
15 ms |
20140 KB |
Output is correct |
17 |
Correct |
12 ms |
19628 KB |
Output is correct |
18 |
Correct |
14 ms |
20044 KB |
Output is correct |
19 |
Runtime error |
41 ms |
40268 KB |
Execution killed with signal 11 |
20 |
Halted |
0 ms |
0 KB |
- |