#include <stdio.h>
#include <algorithm>
#include <vector>
#include <iterator>
using namespace std;
class SegmentTree {
int sz;
vector< vector<int> > t;
void build(int v, int vl, int vr, const vector<int> &a) {
if (vl == vr) {
t[v].push_back(a[vl]);
return;
}
int vm = vl + (vr - vl) / 2;
build(2 * v + 1, vl, vm, a);
build(2 * v + 2, vm + 1, vr, a);
merge(t[2 * v + 1].begin(), t[2 * v + 1].end(), t[2 * v + 2].begin(), t[2 * v + 2].end(), back_inserter(t[v]));
}
int query(int v, int vl, int vr, int l, int r, int k) const {
if (r < vl || vr < l)
return 0;
if (l <= vl && vr <= r)
return t[v].end() - upper_bound(t[v].begin(), t[v].end(), k);
int vm = vl + (vr - vl) / 2;
int ql = query(2 * v + 1, vl, vm, l, r, k);
int qr = query(2 * v + 2, vm + 1, vr, l, r, k);
return ql + qr;
}
public:
SegmentTree(const vector<int> &a) {
sz = a.size();
t.resize(4 * sz);
build(0, 0, sz - 1, a);
}
int query(int l, int r, int k) const {
return query(0, 0, sz - 1, l, r, k);
}
};
int main() {
int aSize;
scanf("%d", &aSize);
vector<int> a(aSize);
for (int i = 0; i < aSize; i++)
scanf("%d", &a[i]);
SegmentTree st(a);
int queriesCount;
scanf("%d", &queriesCount);
for (int i = 0; i < queriesCount; i++) {
int l, r, k;
scanf("%d%d%d", &l, &r, &k);
printf("%d\n", st.query(l - 1, r - 1, k));
}
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxpdGVyYXRvcj4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCgpjbGFzcyBTZWdtZW50VHJlZSB7CgogICAgaW50IHN6OwogICAgdmVjdG9yPCB2ZWN0b3I8aW50PiA+IHQ7CgogICAgdm9pZCBidWlsZChpbnQgdiwgaW50IHZsLCBpbnQgdnIsIGNvbnN0IHZlY3RvcjxpbnQ+ICZhKSB7CiAgICAgICAgaWYgKHZsID09I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