#include <bits/stdc++.h>

using namespace std;

#define maxn 200010
#define gc getchar_unlocked
#define ll long long
//fast I/O
void scanint(int &x)
{
    register int c = gc();
    x = 0;
    bool neg=false;
    if(c=='-')
        neg=true;
    for(;(c<48 || c>57);c = gc());
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg)
        x=-x;
}

struct node{
    int cnt;
    node *left;
    node *right;
    node(){
        this->cnt=0;
        this->left=this;
        this->right=this;
    }
    node(int cnt, node *left, node *right):cnt(cnt), left(left), right(right){}
    node *insert(int L, int R, int val);
    //cnt stores no. of elements, left points to left child and right points to right child
};

node *null; //Base node
node *tree[maxn]; //persistent segment tree

node *node::insert(int L, int R, int val)
{
    if(L==R)
        return new node(this->cnt+1, null, null); //insert no. in node
    else{
        int mid = (L+R)>>1;
        if(val<=mid) //val lies in left child, update left
            return new node(this->cnt+1, this->left->insert(L, mid, val), this->right);
        else // val lies in right child, update right
            return new node(this->cnt+1, this->left, this->right->insert(mid+1, R, val));
    }
}

int query(node *low, node *high, int L, int R, int val) // returns all numbers in given segment that are less than or equal to val
{
    if(L==R)
        return (high->cnt - low->cnt); //can't divide further, return all elements in segment
    int mid = (L+R)>>1;
    int lsum = high->left->cnt - low->left->cnt; // total elements in the left child of segment
    if(val<=mid)
        return query(low->left, high->left, L, mid, val); //val lies in left half, call query on left
    else
        return lsum+query(low->right, high->right, mid+1, R, val); //val lies in right half, add all elements in left half and call query on right half
}

int main()
{
    int n, m, i, j, l, r, k;
    ll curinv, ans, w, x, y, z, q1, q2;
    scanint(n);//no. of elements
    map<int, int> m1;//for coordinate compression
    int arr[n+10], sor[n+10];//arr[] stores values, sor[] stores sorted order of values
    tree[0] = new node();
    for(i=0; i<n; i++){
        scanint(arr[i]);
        m1[arr[i]];
    }
    map<int, int>::iterator it;
    int ind=1;
    for(it=m1.begin(); it!=m1.end(); ++it){
        m1[it->first] = ind;                // coordinate compression and sorting
        sor[ind] = it->first;
        ind++;
    }
    /*for(i=1; i<=n; i++)
        cout << sor[i] << " ";
    cout << endl;
    for(i=0; i<n; i++)
        cout << m1[arr[i]] << " ";
    cout << endl;*/
    for(i=1; i<=n; i++)
        tree[i] = tree[i-1]->insert(0, ind, m1[arr[i-1]]); // inserting val in tree node
    scanint(m); // no. of queries
    while(m--){
        scanint(l); // left index of query
        scanint(r); // right index
        scanint(k); //
       /* if(l>r){
            int temp = l;
            l = r;
            r = temp;
        }*/
        int pos = upper_bound(sor, sor+n+1, k)-(sor); // deciding rank of k in current arr[], kind of doing coordinate compression on k
        //cout << pos << endl;
        k = m1[sor[pos-1]]; // new k after compression
       // cout << k << endl;
       // cout << query(tree[l-1], tree[r], 0, ind, k) << endl;
        ans=(r-l+1-query(tree[l-1], tree[r], 0, ind, k)); //no. of elements greater = total elemnts-no. of elements less than or equal to k
        printf("%d\n", ans);
    }
    return 0;
}
