/*
 * @Author: RMQuan 
 * @Date: 2025-10-26 23:06:34 
 * @Last Modified by: RMQuan
 * @Last Modified time: 2025-10-27 00:07:49
 */
/*idea : 
*/
#include <bits/stdc++.h>
bool M1;
#define ll long long
#define INTMAX INT_MAX
#define INTMIN INT_MIN
#define LONGMAX LLONG_MAX
#define LONGMIN LLONG_MIN
#define fi first
#define se second
#define memfull(a,b) memset(a,b,sizeof(a));
#define endl '\n'
#define TASK "TEST"
#define file() if (fopen(TASK".inp","r")){freopen(TASK".inp","r",stdin); freopen(TASK".out","w",stdout);}
using namespace std;
const int MOD=1e9+7;
const int maxn=1e6+7;
int a[maxn],n,q;
struct ST
{
    int N;
    vector<vector<int> > st1;
    vector<int> st2;
    ST(int _n):N(_n),st1(4*_n+5,vector<int>(0)),st2(4*_n+5,0){}
    pair<int,vector<int> > Merge(int &ans_L,vector<int> &L,int &ans_R,vector<int> &R)
    {
        int cur_ans=max(ans_L,ans_R);
        vector<int> cur_node;
        if (L.size())for (auto i:R)if (i<L[L.size()-1])cur_ans=max(cur_ans,i+L[L.size()-1]);
        int i=0,j=0;
        while (i<L.size()&&j<R.size())
        {
            if (L[i]<R[j])
            {
                cur_node.push_back(L[i]);
                i++;
            }
            else 
            {
                cur_node.push_back(R[j]);
                j++;
            }
        }
        while(i<L.size())
        {
            cur_node.push_back(L[i]);
            i++;
        }
        while (j<R.size())
        {
            cur_node.push_back(R[j]);
            j++;
        }
        return {cur_ans,cur_node};
    }
    void build(int id,int l,int r)
    {
        if (l==r)
        {
            st1[id].push_back(a[l]);
            st2[id]=0;
            return ;
        }
        int mid=(l+r)/2;
        build(id*2,l,mid);
        build(id*2+1,mid+1,r);
        tie(st2[id],st1[id])=Merge(st2[id*2],st1[id*2],st2[id*2+1],st1[id*2+1]);
    }
    pair<int,vector<int> > get(int id,int l,int r,int u,int v)
    {
        if (l>v||r<u)return {0,{}};
        if (l>=u&&r<=v)return {st2[id],st1[id]};
        int mid=(l+r)/2;
        pair<int,vector<int> > L=get(id*2,l,mid,u,v);
        pair<int,vector<int> > R=get(id*2+1,mid+1,r,u,v);
        return Merge(L.fi,L.se,R.fi,R.se);
    }
};
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    file();
    cin>>n>>q;
    for (int i=1;i<=n;i++)cin>>a[i];
    ST st(n);
    st.build(1,1,n);
    while (q--)
    {
        int u,v,k;
        cin>>u>>v>>k;
        cout<<(st.get(1,1,n,u,v).fi<=k?1:0)<<endl;
    }
    bool M2;
    cerr<<"-------------------------------------------------"<<endl;
    cerr<<"Time : "<<clock()<<" ms"<<endl;
    cerr<<"Memory : "<<abs(&M2-&M1)/1024/1024<<" MB"<<endl;
    cerr<<"-------------------------------------------------"<<endl;
    return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
sortbooks.cpp: In function 'int32_t main()':
sortbooks.cpp:24:50: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 | #define file() if (fopen(TASK".inp","r")){freopen(TASK".inp","r",stdin); freopen(TASK".out","w",stdout);}
      |                                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:94:5: note: in expansion of macro 'file'
   94 |     file();
      |     ^~~~
sortbooks.cpp:24:81: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 | #define file() if (fopen(TASK".inp","r")){freopen(TASK".inp","r",stdin); freopen(TASK".out","w",stdout);}
      |                                                                          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:94:5: note: in expansion of macro 'file'
   94 |     file();
      |     ^~~~| # | 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... |