#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

class BinaryIndexedTree
{
private:
    int n;
    vector<int> data;
public:
    BinaryIndexedTree(int n){ // コンストラクタ
        this->n = n;
        data.assign(n+1, 0);
    }
    void add(int k, int x){ // k番目の要素にxを加算する
        ++ k;
        while(k <= n){
            data[k] += x;
            k += k & -k;
        }
    }
    int sum(int k){ // 区間[0,k]の総和を返す
        ++ k;
        int ret = 0;
        while(k > 0){
            ret += data[k];
            k -= k & -k;
        }
        return ret;
    }
    int sum(int a, int b){ // 区間[a,b]の総和を返す
        return sum(b) - sum(a-1);
    }
};

int main()
{
    int n;
    cin >> n;
    vector<int> x(n);
    for(int i=0; i<n; ++i)
        cin >> x[i];

    map<int, int> index;
    for(int i=0; i<n; ++i)
        index[x[i]];
    index[INT_MIN];
    index[INT_MAX];
    int tmp = 0;
    for(auto& p : index){
        p.second = tmp;
        ++ tmp;
    }

    int q;
    cin >> q;
    vector<tuple<int, int, int, int> > v(2*q);
    for(int i=0; i<q; ++i){
        int l, r, e;
        cin >> l >> r >> e;
        int a = min(x[l-1], x[r-1]) - e;
        int b = max(x[l-1], x[r-1]) + e;
        v[2*i] = make_tuple(l-1, a, b, i);
        v[2*i+1] = make_tuple(r, a, b, q+i);
    }
    sort(v.begin(), v.end());

    vector<int> ret(q, 0);
    BinaryIndexedTree bit(index.size());
    int k = 0;
    for(int i=0; i<2*q; ++i){
        int s, a, b, t;
        tie(s, a, b, t) = v[i];

        while(k < s){
            bit.add(index[x[k]], 1);
            ++ k;
        }

        int c = bit.sum(0, (--index.lower_bound(a))->second);
        int d = bit.sum(index.upper_bound(b)->second, index.size() - 1);

        if(t < q)
            ret[t] -= c + d;
        else
            ret[t-q] += c + d;
    }

    for(int i=0; i<q; ++i)
        cout << ret[i] << endl;

    return 0;
}