#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
long long treeMin[4000005],red[1000005],MIN,nex[1000005];
pair<long long,long long>treeMax[4000005],MAX;
void build_tree(long long l,long long r,long long now){
if(l==r){
treeMax[now]=make_pair(red[l],l);
treeMin[now]=red[l];
return ;
}
long long mid=(l+r)/2;
build_tree(l,mid,now*2+1);
build_tree(mid+1,r,now*2+2);
treeMax[now]=max(treeMax[now*2+1],treeMax[now*2+2]);
treeMin[now]=min(treeMin[now*2+1],treeMin[now*2+2]);
//cout<<treeMax[now]<<"-"<<treeMin[now]<<endl;
return ;
}
void find_tree(long long l,long long r,long long L,long long R,long long now){
if(l>=L && r<=R){
//cout<<treeMax[now]<<l<<" "<<r<<endl;
MAX=max(MAX,treeMax[now]);
MIN=min(MIN,treeMin[now]);
return ;
}
if(r<L || l>R){
return ;
}
long long mid=(l+r)/2;
find_tree(l,mid,L,R,now*2+1);
find_tree(mid+1,r,L,R,now*2+2);
}
int main ()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n,m,bob;
cin>>n>>m;
for(long long i=0;i<n;i++)cin>>red[i];
nex[n-1]=n-1;
for(long long i=n-2;i>=0;i--){
if(red[i]<=red[i+1])nex[i]=nex[i+1];
else nex[i]=i;
}
build_tree(0,n-1,0);
for(long long i=0;i<m;i++){
long long l,r,k;
cin>>l>>r>>k;
l--;r--;
MIN=10000000;
MAX=make_pair(-1,0);
find_tree(0,n-1,l,r,0);
if(MAX.second!=l){
if(MAX.first+MIN<=k)cout<<1<<endl;
else cout<<0<<endl;
}else{
bob=MIN;
l=MAX.second+1;
if(l>=n)cout<<1<<endl;
else{
find_tree(0,n-1,l,r,0);
if(MAX.first+bob<=k)cout<<1<<endl;
else cout<<0<<endl;
}
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1090 ms |
70408 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
77 ms |
10188 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |