#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>

using namespace std; using namespace placeholders;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector< int > VI;
typedef vector< vector< int > > VVI;
typedef vector< string > VS;
typedef stringstream SS;
typedef pair< int, int > PII;
typedef vector< pair< int, int > > VPII;
#define VT( T ) vector< T >
#define VVT( T ) vector< vector< T > >
#define LIM( T ) numeric_limits< T >

template < typename T > inline istream& operator>>( istream &s, vector< T > &v ){ for ( T &t : v ) { s >> t; } return s; }
template < typename T > inline ostream& operator<<( ostream &s, const vector< T > &v ){ for ( int i = 0; i < int( v.size() ); ++i ){ s << ( " " + !i ) << v[i]; } return s; }
template < typename T > inline T fromString( const string &s ) { T res; istringstream iss( s ); iss >> res; return res; };
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

#define REP2( i, n ) REP3( i, 0, n )
#define REP3( i, m, n ) for ( int i = ( int )( m ); i < ( int )( n ); ++i )
#define GET_REP( a, b, c, F, ... ) F
#define REP( ... ) GET_REP( __VA_ARGS__, REP3, REP2 )( __VA_ARGS__ )
#define FOR( e, c ) for ( auto &e : c )
#define ALL( c ) ( c ).begin(), ( c ).end()
#define AALL( a, t ) ( t* )a, ( t* )a + sizeof( a ) / sizeof( t )
#define DRANGE( c, p ) ( c ).begin(), ( c ).begin() + p, ( c ).end()

#define SZ( v ) ( (int)( v ).size() )
#define PB push_back
#define EM emplace
#define EB emplace_back
#define BI back_inserter

#define EXIST( c, e ) ( ( c ).find( e ) != ( c ).end() )

#define MP make_pair
#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

// セグメント木のユーティリティ
inline int chl( const int k )
{
	return k * 2 + 1;
}

inline int chr( const int k )
{
	return k * 2 + 2;
}

inline int mid( const int l, const int r )
{
	return ( l + r ) / 2;
}

#define LEFT( k, l, r ) chl( k ), l, mid( l, r )
#define RIGHT( k, l, r ) chr( k ), mid( l, r ), r

struct SegmentTree
{
	const int N;
	VVI data;

	SegmentTree( const VI &src ) : N( SZ( src ) ), data( 4 * N )
	{
		init( src, 0, 0, N );
		return;
	}

	void init( const VI &src, const int k, const int l, const int r )
	{
		if ( l + 1 == r )
		{
			data[k].PB( src[l] );
			return;
		}

		init( src, LEFT( k, l, r  ) );
		init( src, RIGHT( k, l, r ) );

		merge( ALL( data[ chl( k ) ] ), ALL( data[ chr( k ) ] ), BI( data[k] ) );

		return;
	}

	int count( const int x, const int a, const int b, bool less )
	{
		return count( x, a, b, less, 0, 0, N );
	}

	int count( const int x, const int a, const int b, bool less, const int k, const int l, const int r )
	{
		if ( r <= a || b <= l )
		{
			return 0;
		}
		else if ( a <= l && r <= b )
		{
			if ( less )
			{
				return lower_bound( ALL( data[k] ), x ) - data[k].begin();
			}
			else
			{
				return data[k].end() - upper_bound( ALL( data[k] ), x );
			}
		}
		else
		{
			return count( x, a, b, less, LEFT( k, l, r ) ) + count( x, a, b, less, RIGHT( k, l, r ) );
		}
	}
};

int main()
{
	cin.tie( 0 );
	ios::sync_with_stdio( false );

	int D;
	scanf( "%d", &D );

	VI X( D );
	REP( i, D )
	{
		scanf( "%d", &X[i] );
	}

	SegmentTree segtree( X );

	int Q;
	scanf( "%d", &Q );

	REP( iteration, Q )
	{
		int l, r, e;
		scanf( "%d %d %d", &l, &r, &e );
		--l, --r;

		auto mm = minmax( X[l], X[r] );

		printf( "%d\n", segtree.count( mm.fst - e, l, r + 1, true ) + segtree.count( mm.snd + e, l, r + 1, false ) );
	}

	return 0;
}

Measured memory_bytes: 24152