#include<iostream>
#include<vector>
using namespace std;
vector<int> drzewo[2000000];
int wynik[2000000];
int maxx=0;
int wynikk=0;
int pot=1;
void dodaj(int x)
{
wynikk=max(wynikk,wynik[x]);
if(drzewo[x].size()==0)
return;
int mam=drzewo[x].back();
if(maxx==0)
{
maxx=mam;
return;
}
int gdzie=lower_bound(drzewo[x].begin(),drzewo[x].end(),maxx)-drzewo[x].begin();
if(gdzie>=1 && gdzie<=drzewo[x].size())
wynikk=max(wynikk,maxx+drzewo[x][gdzie-1]);
maxx=max(maxx,mam);
}
void zapp(int x,int l,int r,int a,int b)
{
if(l>b || r<a)
return;
if(a<=l && r<=b)
{
dodaj(x);
return;
}
int mid=(l+r)/2;
zapp(x*2,l,mid,a,b);
zapp(x*2+1,mid+1,r,a,b);
}
int32_t main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int n,zap,x;
cin>>n>>zap;
while(pot<=n)
pot*=2;
pot--;
for(int i=1;i<=n;i++)
{
cin>>x;
drzewo[i+pot].push_back(x);
}
for(int i=pot;i>=1;i--)
{
///merguje i*2 z i*2+1
wynik[i]=max(wynik[i*2],wynik[i*2+1]);
if(drzewo[i*2].size()>0)
{
int jest=drzewo[i*2].back();
int gdzie=lower_bound(drzewo[i*2+1].begin(),drzewo[i*2+1].end(),jest)-drzewo[i*2+1].begin();
if(gdzie>=1 && gdzie<=drzewo[i*2+1].size())
wynik[i]=max(wynik[i],jest+drzewo[i*2+1][gdzie-1]);
}
int l=0,r=0;
while(l<drzewo[i*2].size() || r<drzewo[i*2+1].size())
{
if(l==drzewo[i*2].size())
{
drzewo[i].push_back(drzewo[i*2+1][r]);
r++;
continue;
}
if(r==drzewo[i*2+1].size())
{
drzewo[i].push_back(drzewo[i*2][l]);
l++;
continue;
}
if(drzewo[i*2][l]<=drzewo[i*2+1][r])
{
drzewo[i].push_back(drzewo[i*2][l]);
l++;
}
else{
drzewo[i].push_back(drzewo[i*2+1][r]);
r++;
}
}
}
while(zap--)
{
int x,y,z;
cin>>x>>y>>z;
maxx=0;
wynikk=0;
zapp(1,pot+1,pot*2+1,x+pot,y+pot);
//cout<<wynikk<<"\n";
if(wynikk>z)
cout<<"0\n";
else cout<<"1\n";
}
return 0;
}
Compilation message
sortbooks.cpp: In function 'void dodaj(int)':
sortbooks.cpp:21:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | if(gdzie>=1 && gdzie<=drzewo[x].size())
| ~~~~~^~~~~~~~~~~~~~~~~~
sortbooks.cpp: In function 'int32_t main()':
sortbooks.cpp:61:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | if(gdzie>=1 && gdzie<=drzewo[i*2+1].size())
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:65:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | while(l<drzewo[i*2].size() || r<drzewo[i*2+1].size())
| ~^~~~~~~~~~~~~~~~~~~
sortbooks.cpp:65:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | while(l<drzewo[i*2].size() || r<drzewo[i*2+1].size())
| ~^~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:67:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | if(l==drzewo[i*2].size())
| ~^~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:73:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | if(r==drzewo[i*2+1].size())
| ~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
47188 KB |
Output is correct |
2 |
Correct |
24 ms |
47216 KB |
Output is correct |
3 |
Correct |
22 ms |
47240 KB |
Output is correct |
4 |
Correct |
24 ms |
47260 KB |
Output is correct |
5 |
Correct |
22 ms |
47312 KB |
Output is correct |
6 |
Correct |
24 ms |
47292 KB |
Output is correct |
7 |
Correct |
26 ms |
47248 KB |
Output is correct |
8 |
Correct |
24 ms |
47308 KB |
Output is correct |
9 |
Correct |
23 ms |
47260 KB |
Output is correct |
10 |
Correct |
24 ms |
47316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
47188 KB |
Output is correct |
2 |
Correct |
24 ms |
47216 KB |
Output is correct |
3 |
Correct |
22 ms |
47240 KB |
Output is correct |
4 |
Correct |
24 ms |
47260 KB |
Output is correct |
5 |
Correct |
22 ms |
47312 KB |
Output is correct |
6 |
Correct |
24 ms |
47292 KB |
Output is correct |
7 |
Correct |
26 ms |
47248 KB |
Output is correct |
8 |
Correct |
24 ms |
47308 KB |
Output is correct |
9 |
Correct |
23 ms |
47260 KB |
Output is correct |
10 |
Correct |
24 ms |
47316 KB |
Output is correct |
11 |
Correct |
27 ms |
47504 KB |
Output is correct |
12 |
Correct |
26 ms |
47940 KB |
Output is correct |
13 |
Correct |
25 ms |
47876 KB |
Output is correct |
14 |
Correct |
34 ms |
47932 KB |
Output is correct |
15 |
Correct |
33 ms |
47956 KB |
Output is correct |
16 |
Correct |
31 ms |
47980 KB |
Output is correct |
17 |
Correct |
29 ms |
47944 KB |
Output is correct |
18 |
Correct |
30 ms |
47904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
213 ms |
165552 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
185 ms |
62036 KB |
Output is correct |
2 |
Correct |
197 ms |
61968 KB |
Output is correct |
3 |
Correct |
212 ms |
62012 KB |
Output is correct |
4 |
Correct |
173 ms |
62044 KB |
Output is correct |
5 |
Correct |
177 ms |
61972 KB |
Output is correct |
6 |
Correct |
145 ms |
61884 KB |
Output is correct |
7 |
Correct |
137 ms |
61892 KB |
Output is correct |
8 |
Correct |
164 ms |
61640 KB |
Output is correct |
9 |
Correct |
56 ms |
48844 KB |
Output is correct |
10 |
Correct |
201 ms |
61716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
47188 KB |
Output is correct |
2 |
Correct |
24 ms |
47216 KB |
Output is correct |
3 |
Correct |
22 ms |
47240 KB |
Output is correct |
4 |
Correct |
24 ms |
47260 KB |
Output is correct |
5 |
Correct |
22 ms |
47312 KB |
Output is correct |
6 |
Correct |
24 ms |
47292 KB |
Output is correct |
7 |
Correct |
26 ms |
47248 KB |
Output is correct |
8 |
Correct |
24 ms |
47308 KB |
Output is correct |
9 |
Correct |
23 ms |
47260 KB |
Output is correct |
10 |
Correct |
24 ms |
47316 KB |
Output is correct |
11 |
Correct |
27 ms |
47504 KB |
Output is correct |
12 |
Correct |
26 ms |
47940 KB |
Output is correct |
13 |
Correct |
25 ms |
47876 KB |
Output is correct |
14 |
Correct |
34 ms |
47932 KB |
Output is correct |
15 |
Correct |
33 ms |
47956 KB |
Output is correct |
16 |
Correct |
31 ms |
47980 KB |
Output is correct |
17 |
Correct |
29 ms |
47944 KB |
Output is correct |
18 |
Correct |
30 ms |
47904 KB |
Output is correct |
19 |
Correct |
451 ms |
79788 KB |
Output is correct |
20 |
Correct |
472 ms |
80124 KB |
Output is correct |
21 |
Correct |
390 ms |
79648 KB |
Output is correct |
22 |
Correct |
353 ms |
79700 KB |
Output is correct |
23 |
Correct |
400 ms |
79628 KB |
Output is correct |
24 |
Correct |
327 ms |
79572 KB |
Output is correct |
25 |
Correct |
294 ms |
79596 KB |
Output is correct |
26 |
Correct |
400 ms |
79896 KB |
Output is correct |
27 |
Correct |
371 ms |
79776 KB |
Output is correct |
28 |
Correct |
388 ms |
79872 KB |
Output is correct |
29 |
Correct |
466 ms |
80020 KB |
Output is correct |
30 |
Correct |
426 ms |
79840 KB |
Output is correct |
31 |
Correct |
401 ms |
79864 KB |
Output is correct |
32 |
Correct |
421 ms |
79812 KB |
Output is correct |
33 |
Correct |
397 ms |
79876 KB |
Output is correct |
34 |
Correct |
286 ms |
79496 KB |
Output is correct |
35 |
Correct |
331 ms |
79524 KB |
Output is correct |
36 |
Correct |
286 ms |
79472 KB |
Output is correct |
37 |
Correct |
283 ms |
79232 KB |
Output is correct |
38 |
Correct |
275 ms |
79612 KB |
Output is correct |
39 |
Correct |
411 ms |
78468 KB |
Output is correct |
40 |
Correct |
221 ms |
69276 KB |
Output is correct |
41 |
Correct |
356 ms |
78024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
47188 KB |
Output is correct |
2 |
Correct |
24 ms |
47216 KB |
Output is correct |
3 |
Correct |
22 ms |
47240 KB |
Output is correct |
4 |
Correct |
24 ms |
47260 KB |
Output is correct |
5 |
Correct |
22 ms |
47312 KB |
Output is correct |
6 |
Correct |
24 ms |
47292 KB |
Output is correct |
7 |
Correct |
26 ms |
47248 KB |
Output is correct |
8 |
Correct |
24 ms |
47308 KB |
Output is correct |
9 |
Correct |
23 ms |
47260 KB |
Output is correct |
10 |
Correct |
24 ms |
47316 KB |
Output is correct |
11 |
Correct |
27 ms |
47504 KB |
Output is correct |
12 |
Correct |
26 ms |
47940 KB |
Output is correct |
13 |
Correct |
25 ms |
47876 KB |
Output is correct |
14 |
Correct |
34 ms |
47932 KB |
Output is correct |
15 |
Correct |
33 ms |
47956 KB |
Output is correct |
16 |
Correct |
31 ms |
47980 KB |
Output is correct |
17 |
Correct |
29 ms |
47944 KB |
Output is correct |
18 |
Correct |
30 ms |
47904 KB |
Output is correct |
19 |
Runtime error |
213 ms |
165552 KB |
Execution killed with signal 11 |
20 |
Halted |
0 ms |
0 KB |
- |