#include <bits/stdc++.h>
#define endl '\n';
using namespace std;
typedef long long int LL;
struct query{
int l,r,k,id;
}q[200005],tmp;
bool cmp(query q1, query q2){
return q1.k>q2.k;
}
int res[200005],bit[30004];
pair<int,int> v[30004];
void update(int id,int val, int n){
while(id<=n){
bit[id]+=val;
id+=(id)&(-id);
}
}
int query(int id){
int sum=0;
while(id>0){
sum+=bit[id];
id-=(id)&(-id);
}
return sum;
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(0);
//freopen("input.in","r",stdin);
int n;cin>>n;
for(int i=1;i<=n;i++)
{
int x; cin>>x;
v[i-1]=make_pair(x,i);
}
int Q;cin>>Q;for(int i=0;i<Q;i++){
cin>>tmp.l>>tmp.r>>tmp.k;
tmp.id=i;
q[i]=tmp;
}
sort(v,v+n);
sort(q,q+Q,cmp);
int top=n-1;
for(int i=0;i<Q;i++)
{
while(v[top].first>q[i].k){
update(v[top].second,1,n);
top--;
}
int sum=query(q[i].r)-query(q[i].l-1);
res[q[i].id]=sum;
}
for(int i=0;i<Q;i++)cout<<res[i]<<endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgZW5kbCAnXG4nOwp1c2luZyBuYW1lc3BhY2Ugc3RkOwp0eXBlZGVmIGxvbmcgbG9uZyBpbnQgTEw7CgpzdHJ1Y3QgcXVlcnl7CiAgIGludCBsLHIsayxpZDsKfXFbMjAwMDA1XSx0bXA7Cgpib29sIGNtcChxdWVyeSBxMSwgcXVlcnkgcTIpewoJcmV0dXJuIHExLms+cTIuazsKfQoKaW50IHJlc1syMDAwMDVdLGJpdFszMDAwNF07CnBhaXI8aW50LGludD4gdlszMDAwNF07Cgp2b2lkIHVwZGF0ZShpbnQgaWQsaW50IHZhbCwgaW50IG4pewogICAgd2hpbGUoaWQ8PW4pewogICAgICAgIGJpdFtpZF0rPXZhbDsKICAgICAgICBpZCs9KGlkKSYoLWlkKTsKICAgIH0KfQoKaW50IHF1ZXJ5KGludCBpZCl7CiAgIGludCBzdW09MDsKICAgd2hpbGUoaWQ+MCl7CiAgIAkgc3VtKz1iaXRbaWRdOwogICAJIGlkLT0oaWQpJigtaWQpOwogICB9CiAgIHJldHVybiBzdW07Cn0KCmludCBtYWluKCkKewogIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpO2Npbi50aWUoMCk7CgogIC8vZnJlb3BlbigiaW5wdXQuaW4iLCJyIixzdGRpbik7CiAgICAgCiAgICAgaW50IG47Y2luPj5uOwoKICAgICBmb3IoaW50IGk9MTtpPD1uO2krKykKICAgICAgewogICAgICAgICBpbnQgeDsgY2luPj54OwogICAgICAgICB2W2ktMV09bWFrZV9wYWlyKHgsaSk7CiAgICAgIH0KCiAgICAgaW50IFE7Y2luPj5RO2ZvcihpbnQgaT0wO2k8UTtpKyspewogICAgICAgIGNpbj4+dG1wLmw+PnRtcC5yPj50bXAuazsKICAgICAgICB0bXAuaWQ9aTsKICAgICAgICBxW2ldPXRtcDsKICAgICB9IAogICAgIAogICAgIHNvcnQodix2K24pOwogICAgIHNvcnQocSxxK1EsY21wKTsKICAgICAgCiAgICAgaW50IHRvcD1uLTE7CiAgICAgZm9yKGludCBpPTA7aTxRO2krKykKICAgICB7CiAKICAgICAgICB3aGlsZSh2W3RvcF0uZmlyc3Q+cVtpXS5rKXsKICAgICAgICAgICAgdXBkYXRlKHZbdG9wXS5zZWNvbmQsMSxuKTsKICAgICAgICAJdG9wLS07CiAgICAgICAgfQogICAgICAgIGludCBzdW09cXVlcnkocVtpXS5yKS1xdWVyeShxW2ldLmwtMSk7CiAgICAgCXJlc1txW2ldLmlkXT1zdW07CiAgICAgfSAgCgogICAgIGZvcihpbnQgaT0wO2k8UTtpKyspY291dDw8cmVzW2ldPDxlbmRsOyAgICAKICAKICByZXR1cm4gMDsKfQ==