#include<bits/stdc++.h>
using namespace std;

const int sz = 17;
int A[100005];
const int INF = 1 << 30;
const int Backet = 800;
vector< int > v[100005 / Backet];

int main() {
  int D;
  scanf("%d", &D);
  for(int i = 0; i < D; i++) {
    scanf("%d", &A[i]);
    v[i / Backet].push_back(A[i]);
  }
  for(int i = 0; i < D / Backet; i++) {
    sort(v[i].begin(), v[i].end());
  }

  int Q;
  scanf("%d", &Q);
  for(int i = 0; i < Q; i++) {
    int l, r, e;
    scanf("%d %d %d", &l, &r, &e); --l;
    int a = min(A[l], A[r - 1]), b = max(A[l], A[r - 1]);
    int templ = l, tempr = r;
    int cnt = 0;
    while(templ < tempr && templ % Backet) {
      if((A[templ] < a - e) || (A[templ] > b + e)) ++cnt;
      templ++;
    }
    while(templ < tempr && tempr % Backet) {
      --tempr;
      if((A[tempr] < a - e) || (A[tempr] > b + e)) ++cnt;
    }
    while(templ < tempr) {
      int idx = templ / Backet;
      cnt += lower_bound(v[idx].begin(), v[idx].end(), a - e) - v[idx].begin();
      cnt += v[idx].end() - upper_bound(v[idx].begin(), v[idx].end(), b + e);
      templ += Backet;
    }
    printf("%d\n", cnt);
  }
}