#include <bits/stdc++.h>
using namespace std;
#define append push_back
// #define int long long
const int N=1e6+10,LG=21;
int mod=998244353;
int a[N],b[N],tree[N<<2],n,most,mxx;
vector<int>seg[N<<2];
vector<int>v;
void build(int l=1,int r=n,int s=1){
if(l==r){
seg[s]={a[l]};
return;
}
int m=(l+r)>>1;
build(l,m,s*2);
build(m+1,r,s*2+1);
tree[s]=max(tree[s*2],tree[s*2+1]);
if(seg[s*2].back()>seg[s*2+1][0]) tree[s]=max(seg[s*2].back()+*(--lower_bound(seg[s*2+1].begin(),seg[s*2+1].end(),seg[s*2].back())),tree[s]);
seg[s]=seg[s*2];
for(auto i:seg[s*2+1]) seg[s].append(i);
sort(seg[s].begin(),seg[s].end());
}
void get(int a,int b,int l=1,int r=n,int s=1){
if(r<a or l>b) return;
if(a<=l and r<=b){
most=max(most,tree[s]);
if(mxx>seg[s][0]) most=max(most,mxx+*(--lower_bound(seg[s].begin(),seg[s].end(),mxx)));
mxx=max(mxx,seg[s].back());
return;
}
int m=(l+r)>>1;
get(a,b,l,m,s*2);
get(a,b,m+1,r,s*2+1);
}
void solve(int tst){
int m;
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
b[i]=b[i-1];
b[i]+=a[i]>=a[i-1];
}
if(n<=6e5) build();
while(m--){
int a,b_,c;
cin>>a>>b_>>c;
most=mxx=0;
if(n<=6e5) get(a,b_),cout<<(most<=c)<<endl;
else cout<<(b[b_]-b[a]==b_-a)<<endl;
}
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
// cin >> t;
for(int i=1;i<=t;i++){
solve(i);
// if(i!=t) cout<<endl;
}
}
# | 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... |