This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
int n;
int it[1000001];
int aa,bb,cc;
int tree3[4000001];
int tree2[4000001];
void build(int no,int l,int r){
if(l==r){
tree3[no]=it[l];
tree2[no]=it[l];
}
else{
int mid=(l+r)/2;
build(no*2+1,l,mid);
build(no*2+2,mid+1,r);
tree3[no]=max(tree3[no*2+1],tree3[no*2+2]);
if(tree2[no*2+2]==-1 or tree2[no*2+1]==-1){
tree2[no]=-1;
}
else{
if(tree2[no*2+2]<tree3[no*2+1]){
tree2[no]=-1;
}
else{
tree2[no]=tree2[no*2+1];
}
}
}
}
int ans=0;
int ma=0;
int ko=0;
void query(int no,int l,int r,int aa,int bb){
if(r<aa or l>bb){
return;
}
if(aa<=l and r<=bb){
// ans=max(ans,tree2[no]);
if(tree2[no]<ma or tree2[no]==-1){
ans=it[l];
}
ma=max(ma,tree3[no]);
return;
ma=max(tree3[no],ma);
}
else{
int mid=(l+r)/2;
query(no*2+1,l,mid,aa,bb);
query(no*2+2,mid+1,r,aa,bb);
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int m;
cin>>n>>m;
for(int i=0;i<n;i++){
cin>>it[i];
}
build(0,0,n-1);
for(int i=0;i<m;i++){
cin>>aa>>bb>>cc;
aa-=1;
bb-=1;
ans=0;
ma=0;
query(0,0,n-1,aa,bb);
cout<<((ans<=cc)?1:0)<<endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |