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


class SegmentTree {

    int sz;
    vector<int> t;

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

    void modify(int v, int vl, int vr, int pos, int val) {
        if (vl == vr) {
            t[v] += val;
            return;
        }
        int vm = vl + (vr - vl) / 2;
        if (pos <= vm)
            modify(2 * v + 1, vl, vm, pos, val);
        else
            modify(2 * v + 2, vm + 1, vr, pos, val);
        t[v] = t[2 * v + 1] + t[2 * v + 2];
    }

public:

    SegmentTree(int size) {
        sz = size;
        t.resize(4 * sz);
    }

    int size() {
        return sz;
    }

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

    void modify(int pos, int val) {
        modify(0, 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(SegmentTree &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]));
    }

    SegmentTree 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]);
}