#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <vector>
using namespace std;
class SqrtDecomposition {
int size, blockSize, blocksCount;
vector<int> array;
vector< vector<int> > blocks;
public:
SqrtDecomposition(const vector<int> &a) {
array = a;
size = a.size();
blockSize = sqrt(size);
blocksCount = size / blockSize + (size % blockSize ? 1 : 0);
blocks.resize(blocksCount);
for (int i = 0; i < size; i++)
blocks[i / blockSize].push_back(a[i]);
for (int i = 0; i < blocksCount; i++)
sort(blocks[i].begin(), blocks[i].end());
}
int query(int l, int r, int k) const {
int res = 0;
while (l <= r && l % blockSize != 0)
res += array[l++] > k;
while (l <= r && r % blockSize != blockSize - 1)
res += array[r--] > k;
if (l <= r)
for (l /= blockSize, r /= blockSize; l <= r; l++)
res += blocks[l].end() - upper_bound(blocks[l].begin(), blocks[l].end(), k);
return res;
}
};
int main() {
int aSize;
scanf("%d", &aSize);
vector<int> a(aSize);
for (int i = 0; i < aSize; i++)
scanf("%d", &a[i]);
SqrtDecomposition sd(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", sd.query(l - 1, r - 1, k));
}
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxtYXRoLmg+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDx2ZWN0b3I+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgoKY2xhc3MgU3FydERlY29tcG9zaXRpb24gewoKICAgIGludCBzaXplLCBibG9ja1NpemUsIGJsb2Nrc0NvdW50OwogICAgdmVjdG9yPGludD4gYXJyYXk7CiAgICB2ZWN0b3I8IHZlY3RvcjxpbnQ+ID4gYmxvY2tzOwoKcHVibGljOgoKICAgIFNxcnREZWNvbXBvc2l0aW9uKGNvbnN0IHZlY3RvcjxpbnQ+ICZhKSB7CiAgICAgICAgYXJyYXkgPSBhOwogICAgICAgIHNpemUgPSBhLnNpemUoKTsKICAgICAgICBibG9ja1NpemUgPSBzcXJ0KHNpemUpOwogICAgICAgIGJsb2Nrc0NvdW50ID0gc2l6ZSAvIGJsb2NrU2l6ZSArIChzaXplICUgYmxvY2tTaXplID8gMSA6IDApOwogICAgICAgIGJsb2Nrcy5yZXNpemUoYmxvY2tzQ291bnQpOwogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgc2l6ZTsgaSsrKQogICAgICAgICAgICBibG9ja3NbaSAvIGJsb2NrU2l6ZV0ucHVzaF9iYWNrKGFbaV0pOwogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgYmxvY2tzQ291bnQ7IGkrKykKICAgICAgICAgICAgc29ydChibG9ja3NbaV0uYmVnaW4oKSwgYmxvY2tzW2ldLmVuZCgpKTsKICAgIH0KCiAgICBpbnQgcXVlcnkoaW50IGwsIGludCByLCBpbnQgaykgY29uc3QgewogICAgICAgIGludCByZXMgPSAwOwogICAgICAgIHdoaWxlIChsIDw9IHIgJiYgbCAlIGJsb2NrU2l6ZSAhPSAwKQogICAgICAgICAgICByZXMgKz0gYXJyYXlbbCsrXSA+IGs7CiAgICAgICAgd2hpbGUgKGwgPD0gciAmJiByICUgYmxvY2tTaXplICE9IGJsb2NrU2l6ZSAtIDEpCiAgICAgICAgICAgIHJlcyArPSBhcnJheVtyLS1dID4gazsKICAgICAgICBpZiAobCA8PSByKQogICAgICAgICAgICBmb3IgKGwgLz0gYmxvY2tTaXplLCByIC89IGJsb2NrU2l6ZTsgbCA8PSByOyBsKyspCiAgICAgICAgICAgICAgICByZXMgKz0gYmxvY2tzW2xdLmVuZCgpIC0gdXBwZXJfYm91bmQoYmxvY2tzW2xdLmJlZ2luKCksIGJsb2Nrc1tsXS5lbmQoKSwgayk7CiAgICAgICAgcmV0dXJuIHJlczsKICAgIH0KCn07CgoKaW50IG1haW4oKSB7CiAgICBpbnQgYVNpemU7CiAgICBzY2FuZigiJWQiLCAmYVNpemUpOwoKICAgIHZlY3RvcjxpbnQ+IGEoYVNpemUpOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBhU2l6ZTsgaSsrKQogICAgICAgIHNjYW5mKCIlZCIsICZhW2ldKTsKCiAgICBTcXJ0RGVjb21wb3NpdGlvbiBzZChhKTsKCiAgICBpbnQgcXVlcmllc0NvdW50OwogICAgc2NhbmYoIiVkIiwgJnF1ZXJpZXNDb3VudCk7CgogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBxdWVyaWVzQ291bnQ7IGkrKykgewogICAgICAgIGludCBsLCByLCBrOwogICAgICAgIHNjYW5mKCIlZCVkJWQiLCAmbCwgJnIsICZrKTsKICAgICAgICBwcmludGYoIiVkXG4iLCBzZC5xdWVyeShsIC0gMSwgciAtIDEsIGspKTsKICAgIH0KfQ==