#include <vector>
#include <iostream>
#include <queue>
#include <cassert>
#include <tuple>
#include <algorithm>

using namespace std;
typedef long long ll;

template<class D, int S>
struct WaveletTree {
    static const int N = 1<<S;
    typedef pair<D, int> P;
    int n;
    P x[N];
    int d[S+1][N];
    int lc[S][N];

    void built(int l, int r, int dps) {
        if (dps == S) return;
        int pl = l, md = (l+r)/2, pr = md;
        for (int i = l; i < r; i++) {
            if (d[dps][i] < md) {
                d[dps+1][pl++] = d[dps][i];
            } else {
                d[dps+1][pr++] = d[dps][i];
            }
            lc[dps][i] = pl-l;
        }
        built(l, md, dps+1);
        built(md, r, dps+1);
    }

    void init(int nn = N) {
        n = nn;
        for (int i = 0; i < N; i++) {
            x[i].second = i;
        }
        sort(x, x+n);
        for (int i = 0; i < N; i++) {
            d[0][x[i].second] = i;
        }
        built(0, N, 0);
    }
    //[l, r)??§k???????????°????????????
    int get(int l, int r, int k, int dps, int idx) {
        assert(1 <= k && k <= r-l);
        if (dps == S) {
            return d[dps][l];
        }
        int ls = (l > idx ? lc[dps][l-1] : 0);
        int c = lc[dps][r-1] - ls;
        if (k <= c) {
            return get(idx+ls, idx+ls+c, k, dps+1, idx);
        } else {
            int sz = 1<<(S-dps-1);
            return get(l+sz-ls, r+sz-(ls+c), k-c, dps+1, idx+sz);
        }
        return -1;
    }
    D get(int l, int r, int k) {
        return x[get(l, r, k, 0, 0)].first;
    }
    //[l, r)??§x?????????????????§?????????????????????????????????lower_bound
    int find(int l, int r, int x, int dps, int idx) {
        if (r <= l) return 1;
        if (dps == S) {
            return (x <= l) ? 1 : 2;
        }
        int ls = (l > idx ? lc[dps][l-1] : 0);
        int c = lc[dps][r-1] - ls;
        int sz = 1<<(S-dps-1);
        int md = idx+sz;
        if (x <= md) {
            return find(idx+ls, idx+ls+c, x, dps+1, idx);
        } else {
            return c+find(l+sz-ls, r+sz-(ls+c), x, dps+1, idx+sz);
        }
    }
    int find(int l, int r, D u) {
        return find(l, r, lower_bound(x, x+n, P(u, -1)) - x, 0, 0);
    }
};

WaveletTree<int, 17> st;
//StarrySkyTree<17> st;
int x[1<<17];

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> x[i];
        st.x[i].first = x[i];
//        st.add(i, x[i]);
    }
    st.init(n);
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int l, r, e;
        cin >> l >> r >> e; l--;
        int mi = min(x[l], x[r-1]);
        int ma = max(x[l], x[r-1]);
        mi -= e;
        ma += e+1;
        int res = st.find(l, r, mi) + ((r-l) - st.find(l, r, ma));
        cout << res << endl;
    }
    return 0;
}    