#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
int s=0;
bool f=false;
char c=getchar();
while(!isdigit(c))
{
f=(c=='-');
c=getchar();
}
while(isdigit(c))
{
s=(s<<3)+(s<<1)+c-'0';
c=getchar();
}
return f?-s:s;
}
void write(int x)
{
if(x<0)
{
x=-x;
putchar('-');
return;
}
if(x>9)
{
write(x/10);
}
putchar(x%10+'0');
}
int n,m,cnt=1;
struct qry
{
int id,l,r,h,ans;
bool operator <(const qry &b)const
{
return h>b.h;
}
}q[200005];
bool a[200005];
struct node
{
int l,r,s;
}t[200005<<2];
struct pos
{
int id,h;
bool operator <(const pos &b)const
{
return h>b.h;
}
}pt[200005];
inline int ls(int x)
{
return x<<1;
}
inline int rs(int x)
{
return x<<1|1;
}
inline void pushup(int p)
{
t[p].s=t[ls(p)].s+t[rs(p)].s-(a[t[ls(p)].r]&&a[t[rs(p)].l]);
}
void build(int p,int pl,int pr)
{
t[p].l=pl;
t[p].r=pr;
t[p].s=0;
if(pl==pr)
{
return;
}
int mid=(pl+pr)>>1;
build(ls(p),pl,mid);
build(rs(p),mid+1,pr);
pushup(p);
}
void update(int p,int i)
{
if(t[p].l==t[p].r)
{
t[p].s=true;
return;
}
int mid=(t[p].l+t[p].r)>>1;
if(i<=mid)
update(ls(p),i);
else
update(rs(p),i);
pushup(p);
}
int query(int p,int l,int r)
{
if(t[p].l==t[p].r)
{
return t[p].s;
}
int res=0,mid=(t[p].l+t[p].r)>>1;
if(l<=mid)
{
res+=query(ls(p),l,r);
}
if(r>mid)
{
res+=query(rs(p),l,r);
}
res-=((l<=mid)&&(r>mid)&&(a[t[rs(p)].l])&&(a[t[ls(p)].r]));
return res;
}
signed main()
{
n=read();
m=read();
for(int i=1;i<=n;i++)
{
pt[pt[i].id=i].h=read();
}
sort(pt+1,pt+n+1);
build(1,1,n);
for(int i=1;i<=m;i++)
{
q[i].id=i;
q[i].l=read();
q[i].r=read();
q[i].h=read();
}
sort(q+1,q+m+1);
for(int i=1;i<=m;i++)
{
while(pt[cnt].h>q[i].h&&cnt<=n)
{
a[pt[cnt].id]=true;
update(1,pt[cnt].id);
cnt++;
}
q[q[i].id].ans=query(1,q[i].l,q[i].r);
}
for(int i=1;i<=m;i++)
{
write(q[i].ans);
putchar('\n');
}
return 0;
}