#include<bits/stdc++.h>
using namespace std;
#define up(i,l,r) for(int i=l;i<=r;++i)
#define dn(i,l,r) for(int i=l;i>=r;--i)
#define low(x) x&-x
const int N=4e6+5;
const int K=2e6;
int s[N];
struct node{
int l,r,xx,id;
}t[N];
bool cmp1(node x,node y){
return x.l<y.l;
}
bool cmp2(node x,node y){
return x.r<y.r;
}
int ans_l[N],ans_r[N],n,q,a[N];
void upd(int x,int k){
while(x<=K){
s[x]+=k;x+=low(x);
}
}
int que(int x){
int ans=0;
while(x){
ans+=s[x];x-=low(x);
}
return ans;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin>>n>>q;
up(i,1,n) cin>>a[i];
up(i,1,q) cin>>t[i].l>>t[i].r>>t[i].xx;
up(i,1,q) t[i].l--;
up(i,1,q) t[i].id=i;
sort(t+1,t+q+1,cmp1);
int j=1;
up(i,1,q){
while(j<=t[i].l){
upd(a[j],1);
++j;
}
ans_l[t[i].id]=que(t[i].xx);
}
sort(t+1,t+q+1,cmp2);
j=1;
up(i,1,q){
while(j<=t[i].r){
upd(a[j],1);++j;
}
ans_r[t[i].id]=que(t[i].xx);
}
up(i,1,q){
cout<<ans_r[i]-ans_l[i]<<'\n';
}
return 0;
}