object Main extends App {
  import scala.io.StdIn._

  val d = readInt
  val numbers = readLine.trim.split(' ').map(_.toInt)
  val segTree = SegTree(numbers)
  for (_ ← 0 until readInt){
    val Array(l, r, e) = readLine.trim.split(' ').map(_.toInt)
    val a = math.min(numbers(l - 1), numbers(r - 1))
    val b = math.max(numbers(l - 1), numbers(r - 1))
    println(r - l + 1 - segTree.countInRange(l - 1, r, a - e, b + e))
  }
  object SegTree{
    sealed trait Tree extends SegTree
    private class Node(private val mFrom: Int, private val mUntil: Int, private val mLeft: Tree, private val mRight: Tree, private[this] val mArray: Array[Int]) extends Tree {
      override def countInRange(from: Int, until: Int, lower: Int, upper: Int): Int = {
        if (from <= mFrom && mUntil <= until) upperBound(mArray, upper) - lowerBound(mArray, lower)
        else if (mUntil <= from || until <= mFrom) 0
        else mLeft.countInRange(from, until, lower, upper) + mRight.countInRange(from, until, lower, upper)
      }
    }
    private class Leaf(private val mFrom: Int, private val mUntil: Int, private[this] val mArray: Array[Int]) extends Tree {
      override def countInRange(from: Int, until: Int, lower: Int, upper: Int): Int = {
        (math.max(from, mFrom) until math.min(until, mUntil)).count(i ⇒ lower <= mArray(i - mFrom) && mArray(i - mFrom) <= upper)
      }
    }
    private[this] def lowerBound(array: Array[Int], target: Int): Int = {
      var left = 0
      var right = array.length
      while (left < right){
        val mid = (left + right) / 2
        if (array(mid) < target){
          left = mid + 1
        }else {
          right = mid
        }
      }
      right
    }
    private[this] def upperBound(array: Array[Int], target: Int): Int = {
      var left = 0
      var right = array.length
      while(left < right){
        val mid = (left + right) / 2
        if (array(mid) <= target){
          left = mid + 1
        }else {
          right = mid
        }
      }
      right
    }
    def apply(numbers: Array[Int]): Tree = {
      makeTree(numbers, 0, numbers.length)
    }
    private[this] def makeTree(array: Array[Int], from: Int, until: Int): Tree = {
      if (until - from >= 16) new Node(from, until, makeTree(array, from, (from + until) / 2), makeTree(array, (from + until) / 2, until), (from until until).map(array).sorted.toArray)
      else new Leaf(from, until, (from until until).map(array).toArray)
    }
  }
  trait SegTree {
    def countInRange(from: Int, until: Int, lower: Int, upper: Int): Int
  }
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def also(@inline func: T ⇒ Unit): T = {
      func(value)
      value
    }
    @inline
    def let[A](@inline func: T ⇒ A): A = func(value)
  }
}
