#include<bits/stdc++.h>

using namespace std;

enum {
    NOTFOUND = 0xFFFFFFFFU
};

class SuccinctBitVector {
private:
    unsigned int size;
    const int blockSize = (1 << 5); // 32(unsigned intのbit数)
    vector<unsigned int> B;

    const int LEVEL_L = (1 << 9);   // 512
    const int LEVEL_S = (1 << 5);   // 32
    vector<unsigned char> L;        // 大ブロック
    vector<unsigned int> S;         // 小ブロック

    unsigned int numOfOne = 0;

public:
    explicit SuccinctBitVector(unsigned int n) {
        this->size = n;
        unsigned int s = (n + blockSize - 1) / blockSize + 1;   // ceil(n, blockSize)
        this->B.assign(s, 0);

        unsigned int L_size = n / LEVEL_L + 1;
        unsigned int S_size = n / LEVEL_S + 1;
        this->L.assign(L_size, 0);
        this->S.assign(S_size, 0);
    }

    // B[pos] = bit
    void setBit(unsigned int bit, unsigned int pos){
        assert(bit == 0 or bit == 1);
        assert(0 <= pos and pos < this->size);
        unsigned int blockPos = pos / blockSize;
        unsigned int offset = pos % blockSize;
        if (bit == 1) { B.at(blockPos) |= (1U << offset); }
        else          { B.at(blockPos) &= (~(1U << offset)); }
    }

    // B[pos]
    unsigned int access(unsigned int pos) {
        assert(0 <= pos and pos < this->size);
        unsigned int blockPos = pos / blockSize;
        unsigned int offset   = pos % blockSize;
        return ((B.at(blockPos) >> offset) & 1);
    }

    void build(){
        unsigned int num = 0;
        for (unsigned int i = 0; i <= size; i++){
            if (i % LEVEL_L == 0) {
                L.at(i / LEVEL_L) = num;
            }
            if (i % LEVEL_S == 0) {
                S.at(i / LEVEL_S) = num - L.at(i / LEVEL_L);
            }
            if (i != size and i % blockSize == 0) {
                num += __builtin_popcount(this->getBlock(i / blockSize));
            }
        }
        this->numOfOne = num;
    }

    // B[0, pos)のbitの数
    unsigned int rank(unsigned int bit, unsigned int pos) {
        assert(bit == 0 or bit == 1);
        assert(0 <= pos and pos <= this->size);

        if (bit) { return rank1(pos); }
        else     { return pos - rank1(pos); }
    }

    // rank番目のbitの位置 + 1(rankは1-origin)
    unsigned int select(unsigned int bit, unsigned int rank) {
        assert(bit == 0 or bit == 1);
        assert(rank > 0);
        if (bit == 0 and rank > this->size - this->numOfOne ) { return NOTFOUND; }
        if (bit == 1 and rank > this->numOfOne )              { return NOTFOUND; }

        // [lb, ub)
        unsigned int left = 0, right = this->size + 1;
        while(right - left > 1) {
            unsigned int mid = (left + right) / 2;
            if(this->rank(bit, mid) < rank) {
                left = mid;
            }
            else {
                right = mid;
            }
        }

        return left + 1;
    }

    unsigned int getNumOfOne() const {
        return numOfOne;
    }

private:
    unsigned int rank1(unsigned int pos) {
        const unsigned int remain = pos % LEVEL_S;
        const unsigned int blockP = remain / blockSize;
        const unsigned int remainP = remain % blockSize;
        return L.at(pos / LEVEL_L) + S.at(pos / LEVEL_S) + __builtin_popcount(this->getBlock(pos / blockSize) & ((1 << remainP) - 1));
    }

    unsigned int getBlock(unsigned int pos) const {
        return this->B.at(pos);
    }
};

class WaveletMatrix {
private:
    vector<SuccinctBitVector> bit_arrays;
    vector<unsigned int> begin_one;          // 各bitに着目したときの1の開始位置
    map<unsigned int, unsigned int> begin_alphabet;   // 最後のソートされた配列で各文字の開始位置

    unsigned int num_of_alphabet;            // 文字数
    unsigned int num_of_bit;                 // 文字を表すのに必要なbit数
    unsigned int len;                        // 与えられた配列のサイズ

public:
    explicit WaveletMatrix (const vector<unsigned int> &v) {
        assert(v.size() > 0);
        num_of_alphabet =  *max_element(v.begin(), v.end()) + 1;
        num_of_bit = get_num_of_bit(num_of_alphabet);
        if (num_of_bit == 0) {
            num_of_bit = 1;
        }
        len = static_cast<unsigned int>(v.size());

        this->build(v);
    }

    // v[pos]
    unsigned int access(unsigned int pos) {
        if (pos >= this->len) { return NOTFOUND; }

        unsigned int c = 0;
        for (unsigned int i = 0; i < bit_arrays.size(); ++i) {
            unsigned bit = bit_arrays.at(i).access(pos);   // もとの数値がのi番目のbit
            c = (c <<= 1) | bit;
            pos = bit_arrays.at(i).rank(bit, pos);
            if (bit) {
                pos += this->begin_one.at(i);
            }
        }
        return c;
    }

    // i番目のcの位置 + 1を返す。rankは1-origin
    unsigned int select(unsigned int c, unsigned int rank) {
        assert(rank > 0);
        if (c >= num_of_alphabet) {
            return NOTFOUND;
        }
        if (this->begin_alphabet.find(c) == this->begin_alphabet.end()) {
            return NOTFOUND;
        }

        unsigned int index = this->begin_alphabet.at(c) + rank;
        for (size_t i = 0; i < bit_arrays.size(); ++i){
            unsigned int bit = ((c >> i) & 1);      // 下からi番目のbit
            if (bit == 1) {
                index -= this->begin_one.at(num_of_bit - i - 1);
            }
            index = this->bit_arrays.at(num_of_bit - i - 1).select(bit, index);
        }
        return index;
    }

    // v[begin_pos, end_pos)で最大値のindexを返す
    unsigned int maxRange(unsigned int begin_pos, unsigned int end_pos) {
        return quantileRange(begin_pos, end_pos, end_pos - begin_pos - 1);
    }

    // v[begin_pos, end_pos)で最小値のindexを返す
    unsigned int minRange(unsigned int begin_pos, unsigned int end_pos) {
        return quantileRange(begin_pos, end_pos, 0);
    }

    // v[begin_pos, end_pos)でk番目に小さい数値のindexを返す(kは0-origin)
    // つまり小さい順に並べてk番目の値
    unsigned int quantileRange(unsigned int begin_pos, unsigned int end_pos, unsigned int k) {
        if ((end_pos > len || begin_pos >= end_pos) || (k >= end_pos - begin_pos)) {
            return NOTFOUND;
        }

        unsigned int val = 0;
        for (size_t i = 0; i < num_of_bit; ++i) {
            unsigned int num_of_zero_begin = bit_arrays.at(i).rank(0, begin_pos);
            unsigned int num_of_zero_end = bit_arrays.at(i).rank(0, end_pos);
            unsigned int num_of_zero = num_of_zero_end - num_of_zero_begin;     // beginからendまでにある0の数
            unsigned int bit = (k < num_of_zero) ? 0 : 1;                       // k番目の値の上からi番目のbitが0か1か

            if (bit) {
                k -= num_of_zero;
                begin_pos = this->begin_one.at(i) + begin_pos - num_of_zero_begin;
                end_pos = this->begin_one.at(i) + end_pos - num_of_zero_end;
            }
            else {
                begin_pos = num_of_zero_begin;
                end_pos = num_of_zero_begin + num_of_zero;
            }

            val = ((val << 1) | bit);
        }

        unsigned int rank = begin_pos + k - this->begin_alphabet.at(val) + 1;
        return select(val, rank) - 1;
    }

    // v[0, pos)のcの数
    unsigned int rank(unsigned int c, unsigned int pos) {
        if (c >= num_of_alphabet or pos > len) {
            return NOTFOUND;
        }
        if (this->begin_alphabet.find(c) == this->begin_alphabet.end()) {
            return NOTFOUND;
        }

        for (unsigned int i = 0; i < num_of_bit; ++i) {
            unsigned int bit = (c >> (num_of_bit - i - 1)) & 1;  // 上からi番目のbit
            pos = bit_arrays.at(i).rank(bit, pos);               // cのi番目のbitと同じ数値の数
            if (bit) {
                pos += this->begin_one.at(i);
            }
        }

        unsigned int begin_pos = this->begin_alphabet.at(c);
        return pos - begin_pos;
    }

    // v[0, pos)でcより小さい文字の数
    unsigned int rankLessThan(unsigned int c, unsigned int pos) {
        unsigned int rank_less_than = 0, rank_more_than = 0, rank = 0;
        rankAll(c, 0, pos, rank, rank_less_than, rank_more_than);
        return rank_less_than;
    }

    // v[0, pos)でcより大きい文字の数
    unsigned int rankMoreThan(unsigned int c, unsigned int pos) {
        unsigned int rank_less_than = 0, rank_more_than = 0, rank = 0;
        rankAll(c, 0, pos, rank, rank_less_than, rank_more_than);
        return rank_more_than;
    }

    // v[begin_pos, end_pos)でcと同じ値の数、cより小さい値の数、cより大きい値の数を求める
    void rankAll(unsigned int c, unsigned int begin_pos, unsigned int end_pos, unsigned int &rank, unsigned int &rank_less_than, unsigned int &rank_more_than) {
        if (c >= num_of_alphabet || begin_pos >= len || end_pos > len) {
            rank_less_than = NOTFOUND;
            rank_more_than = NOTFOUND;
            rank           = NOTFOUND;
            return;
        }
        rank_less_than = 0;
        rank_more_than = 0;
        rank = 0;

        if (begin_pos >= end_pos) {
            return;
        }

        vector<unsigned int> more_and_less(2, 0);
        for (unsigned int i = 0; i < num_of_bit; ++i) {
            const unsigned int bit = (c >> (num_of_bit - i - 1)) & 1;

            const unsigned int range_bits = end_pos - begin_pos;
            const unsigned int begin_zero = bit_arrays.at(i).rank(0, begin_pos);
            const unsigned int end_zero = bit_arrays.at(i).rank(0, end_pos);

            if (bit) {
                begin_pos += this->begin_one.at(i) - begin_zero;
                end_pos += this->begin_one.at(i) - end_zero;
            } else {
                begin_pos = begin_zero;
                end_pos = end_zero;
            }
            more_and_less.at(bit) += range_bits - (end_pos - begin_pos);
        }

        rank_less_than = more_and_less.at(1);
        rank_more_than = more_and_less.at(0);
        rank = end_pos - begin_pos;
    }


private:
    unsigned int get_num_of_bit(unsigned int x) {
        if (x == 0) return 0;
        x--;
        unsigned int bit_num = 0;
        while (x >> bit_num) {
            ++bit_num;
        }
        return bit_num;
    }

    void build(const vector<unsigned int> &array) {
        if (num_of_alphabet == 0) { return; }
        for (int i = 0; i < num_of_bit; ++i) {
            SuccinctBitVector sv(len);
            bit_arrays.push_back(sv);
        }
        this->begin_one.resize(num_of_bit);

        vector<unsigned int> v(array);
        for (unsigned int i = 0; i < num_of_bit; ++i) {

            vector<unsigned int> temp;
            // 0をtempにいれてく
            for (unsigned int j = 0; j < v.size(); ++j) {
                unsigned int c = v.at(j);
                unsigned int bit = (c >> (num_of_bit - i - 1)) & 1;  //　上からi番目のbit
                if (bit == 0) {
                    temp.push_back(c);
                    bit_arrays.at(i).setBit(0, j);
                }
            }

            this->begin_one.at(i) = temp.size();

            // 1をtempにいれてく
            for (unsigned int j = 0; j < v.size(); ++j) {
                unsigned int c = v.at(j);
                unsigned int bit = (c >> (num_of_bit - i - 1)) & 1;  //　上からi番目のbit
                if (bit == 1) {
                    temp.push_back(c);
                    bit_arrays.at(i).setBit(1, j);
                }
            }

            bit_arrays.at(i).build();
            v = temp;
        }

        // ソートされた配列内での各文字の位置を取得
        for (int i = v.size() - 1; i >= 0; --i) {
            this->begin_alphabet[v.at(i)] = i;
        }
    }
};

int main() {
    const unsigned int BASE = 100000001;
    unsigned int D, Q, l, r, e;
    int x;
    cin >> D;
    vector<unsigned int> v(D);
    for (int i = 0; i < D; ++i) {
        cin >> x;
        v[i] = x + BASE;
    }

    WaveletMatrix wm(v);

    cin >> Q;
    for (int i = 0; i < Q; ++i) {
        cin >> l >> r >> e;
        l--; r--;
        unsigned int a = min(v[l], v[r]);
        unsigned int b = max(v[l], v[r]);
        unsigned int ans = 0;
        ans += wm.rankLessThan(a - e, r + 1) - wm.rankLessThan(a - e, l);
        ans += wm.rankMoreThan(b + e, r + 1) - wm.rankMoreThan(b + e, l);
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 9104