// Slower C++ solution:
#include <vector>

#include <iostream>

#include <algorithm>

using namespace std;

int D, Q, x[131072], ls, rs, es, a, b; vector<int> seg[262144];

int query(int k, int l, int r) {

	if (r <= ls || rs <= l) return 0;

	if (ls <= l && r <= rs) return lower_bound(seg[k].begin(), seg[k].end(), b) - lower_bound(seg[k].begin(), seg[k].end(), a);

	int lc = query(2 * k, l, (l + r) / 2);

	int rc = query(2 * k + 1, (l + r) / 2, r);

	return lc + rc;

}

int main() {

	scanf("%d", &D);

	for (int i = 0; i < D; i++) {

		scanf("%d", &x[i]);

		int t = i + 131072;

		while (t > 0) {

			seg[t].push_back(x[i]);

			t >>= 1;

		}

	}

	for (int i = 1; i < 262144; i++) {

		if (seg[i].size() > 1) {

			sort(seg[i].begin(), seg[i].end());

		}

	}

	scanf("%d", &Q);

	for (int i = 0; i < Q; i++) {

		scanf("%d%d%d", &ls, &rs, &es); ls--;

		a = min(x[ls], x[rs - 1]) - es;

		b = max(x[ls], x[rs - 1]) + es + 1;

		printf("%d\n", rs - ls - query(1, 0, 131072));

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 10.296182776142604x):
#ifndef ___Class_RangeTree

#define ___Class_RangeTree



// ------ Includes ------ //

#include <limits>

#include <vector>

#include <algorithm>



template<typename Type> class RangeTree {

private:

	int size_;

	std::vector<std::vector<Type> > dat;

	std::vector<std::vector<int> > vl;

	inline int query_(int a, int b, Type x, int k, int l, int r, int e) {

		// Find range [a, b) : value < x : Now k-th node and the range is [l, r) and e integers below x in the range

		if (r <= a || b <= l || e == 0) return 0;

		if (a <= l && r <= b) return e;

		int lc = query_(a, b, x, k << 1, l, (l + r) >> 1, vl[k][e - 1]);

		int rc = query_(a, b, x, k << 1 | 1, (l + r) >> 1, r, e - vl[k][e - 1]);

		return lc + rc;

	}

public:

	RangeTree() : size_(0), dat(std::vector<Type>()) {};

	template<class T>

	RangeTree(T begin_, T end_) {

		int n = (end_ - begin_);

		for (size_ = 1; size_ < n; size_ <<= 1);

		dat.resize(size_ << 1);

		vl.resize(size_);

		for (int i = 0; i < n; i++) dat[i + size_].push_back(*(begin_ + i));

		for (int i = size_ - 1; i > 0; i--) {

			dat[i].resize(dat[i << 1].size() + dat[i << 1 | 1].size());

			vl[i].resize(dat[i].size());

			int cl = 0;

			for (int j = 0; j < dat[i].size(); j++) {

				if (j - cl == dat[i << 1 | 1].size() || (cl != dat[i << 1].size() && dat[i << 1][cl] < dat[i << 1 | 1][j - cl])) dat[i][j] = dat[i << 1][cl++];

				else dat[i][j] = dat[i << 1 | 1][j - cl];

				vl[i][j] = cl;

			}

		}

	}

	inline int size() { return size_; }

	inline int query(int l, int r, Type x) {

		// Find range [a, b) : value < x

		int ptr = lower_bound(dat[1].begin(), dat[1].end(), x) - dat[1].begin();

		return query_(l, r, x, 1, 0, size_, ptr);

	}

};



#endif



#include <cstdio>

#include <vector>

#include <algorithm>

#pragma warning(disable : 4996)

using namespace std;

int n, q, l, r, e;

int main() {

	scanf("%d", &n);

	vector<int> a(n);

	for (int i = 0; i < n; i++) scanf("%d", &a[i]);

	RangeTree<int> seg(a.begin(), a.end());

	scanf("%d", &q);

	while (q--) {

		scanf("%d%d%d", &l, &r, &e); l--;

		int x1 = seg.query(l, r, min(a[l], a[r - 1]) - e);

		int x2 = seg.query(l, r, max(a[l], a[r - 1]) + e + 1);

		printf("%d\n", (r - l) - (x2 - x1));

	}

	return 0;

}