#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;


class ImplicitSegmentTree {

    int sz;
    struct Node {
        int s;
        Node *l, *r;
        Node() : s(0), l(0), r(0) {}
    } *root;

    int query(Node *v, int vl, int vr, int l, int r) const {
        if (!v || r < vl || vr < l)
            return 0;
        if (l <= vl && vr <= r)
            return v->s;
        int vm = vl + (vr - vl) / 2;
        int ql = query(v->l, vl, vm, l, r);
        int qr = query(v->r, vm + 1, vr, l, r);
        return ql + qr;
    }

    void modify(Node *v, int vl, int vr, int pos, int val) {
        if (vl == vr) {
            v->s += val;
            return;
        }
        int vm = vl + (vr - vl) / 2;
        if (pos <= vm) {
            if (!v->l)
                v->l = new Node();
            modify(v->l, vl, vm, pos, val);
        } else {
            if (!v->r)
                v->r = new Node();
            modify(v->r, vm + 1, vr, pos, val);
        }
        v->s = (v->l ? v->l->s : 0) + (v->r ? v->r->s : 0);
    }

    void destroy(Node *v) {
        if (v->l)
            destroy(v->l);
        if (v->r)
            destroy(v->r);
        delete v;
    }

public:

    ImplicitSegmentTree(int size) {
        sz = size;
        root = new Node();
    }

    ~ImplicitSegmentTree() {
        destroy(root);
    }

    int size() {
        return sz;
    }

    int query(int l, int r) const {
        return query(root, 0, sz - 1, l, r);
    }

    void modify(int pos, int val) {
        modify(root, 0, sz - 1, pos, val);
    }

};


class Event {

    int type, index, x, y;

public:

    Event(int type, int index, int x, int y) : type(type), index(index), x(x), y(y) {}
    
    bool operator < (const Event &that) const {
        return x < that.x || x == that.x && type < that.type;
    }

    void process(ImplicitSegmentTree &st, vector<int> &answers) const {
        int k = st.query(y + 1, st.size() - 1);
        if (type == 1)
            answers[index] -= st.query(y + 1, st.size() - 1);
        if (type == 2)
            st.modify(y, 1);
        if (type == 3)
            answers[index] += st.query(y + 1, st.size() - 1);
    }

};


int main() {
    vector<Event> scanLine;

    int aSize, aMax = 0;
    scanf("%d", &aSize);

    vector<int> a(aSize);
    for (int i = 0; i < aSize; i++) {
        scanf("%d", &a[i]);
        aMax = max(aMax, a[i]);
        scanLine.push_back(Event(2, -1, i, a[i]));
    }

    ImplicitSegmentTree st(aMax + 1);

    int queriesCount;
    scanf("%d", &queriesCount);

    for (int i = 0; i < queriesCount; i++) {
        int l, r, k;
        scanf("%d%d%d", &l, &r, &k);
        scanLine.push_back(Event(1, i, l - 1, k));
        scanLine.push_back(Event(3, i, r - 1, k));
    }

    vector<int> answers(queriesCount);
    sort(scanLine.begin(), scanLine.end());
    for (int i = 0; i < scanLine.size(); i++)
        scanLine[i].process(st, answers);

    for (int i = 0; i < queriesCount; i++)
        printf("%d\n", answers[i]);
}