#include<iostream>
#include<set>
using namespace std;
set<int> drzewo[3000000];
int wynik[3000000];
int maxx=0;
int wynikk=0;
int pot=1;
void dodaj(int x)
{
wynikk=max(wynikk,wynik[x]);
if(drzewo[x].size()==0)
return;
auto it=drzewo[x].end();
it--;
int mam=*it;
if(maxx==0)
{
maxx=mam;
return;
}
auto it2=drzewo[x].lower_bound(maxx);
if(it2!=drzewo[x].begin())
{
it2--;
if(it2!=drzewo[x].end())
wynikk=max(wynikk,maxx+*it2);
}
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].insert(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)
{
auto it=drzewo[i*2].end();
it--;
int jest=*it;
auto it2=drzewo[i*2+1].lower_bound(jest);
if(it2==drzewo[i*2+1].begin())
continue;
it2--;
if(it2!=drzewo[i*2+1].end())
wynik[i]=max(wynik[i],jest+*it2);
}
drzewo[i]=drzewo[i*2];
for(auto it=drzewo[i*2+1].begin();it!=drzewo[i*2+1].end();it++)
drzewo[i].insert(*it);
}
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);
if(wynikk>z)
cout<<"0\n";
else cout<<"1\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
141216 KB |
Output is correct |
2 |
Correct |
61 ms |
141128 KB |
Output is correct |
3 |
Incorrect |
64 ms |
141188 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
141216 KB |
Output is correct |
2 |
Correct |
61 ms |
141128 KB |
Output is correct |
3 |
Incorrect |
64 ms |
141188 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
316 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
244 ms |
155852 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
141216 KB |
Output is correct |
2 |
Correct |
61 ms |
141128 KB |
Output is correct |
3 |
Incorrect |
64 ms |
141188 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
141216 KB |
Output is correct |
2 |
Correct |
61 ms |
141128 KB |
Output is correct |
3 |
Incorrect |
64 ms |
141188 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |