#include<bits/stdc++.h>
using namespace std;
int n,a[1000001],stk[1000001],ans[1000001],tree[1000001];
struct node{
int l,r,val,id;
};
node f[2000001];
bool cmp(node x,node y)
{
return x.l>y.l||x.l==y.l&&(x.r<y.r||x.r==y.r&&x.id<y.id);
}
int lowbit(int x)
{
return x&-x;
}
void edit(int x,int k)
{
while(x<=n)
{
tree[x]=max(tree[x],k);
x+=lowbit(x);
}
}
int query(int x)
{
int ans=0;
while(x>0)
{
ans=max(ans,tree[x]);
x-=lowbit(x);
}
return ans;
}
int main()
{
// freopen("c.in","r",stdin);
// freopen("c.out","w",stdout);
int m,cnt,top;
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>a[i];
top=0;
cnt=0;
for(int i=1;i<=n;i++)
{
while(top>0&&a[i]>=a[stk[top]])
top--;
if(top>0)
{
cnt++;
f[cnt].l=stk[top];
f[cnt].r=i;
f[cnt].val=a[i]+a[stk[top]];
f[cnt].id=0;
}
stk[++top]=i;
}
for(int i=1;i<=m;i++)
{
cnt++;
cin>>f[cnt].l>>f[cnt].r>>f[cnt].val;
f[cnt].id=i;
}
sort(f+1,f+cnt+1,cmp);
for(int i=1;i<=cnt;i++)
if(f[i].id==0)
edit(f[i].r,f[i].val);
else
if(query(f[i].r)<=f[i].val)
ans[f[i].id]=1;
else
ans[f[i].id]=0;
for(int i=1;i<=m;i++)
cout<<ans[i]<<endl;
return 0;
}123
这是 2026年10月12日 存档的第 1 版,不是当前版本。查看当前版本