#include <bits/stdc++.h>
using namespace std;
const int MX = 2e5 + 7;
const int MXN = 240000;
typedef pair<int,int> pii;
typedef pair<pii, int> piii;
#define f first
#define s second
int SZ, n, q, Arr[MX], Ans[MX], K[MX], tree[MXN];
piii queries[MX];
bool cmp(const piii &x, const piii &y){
int _x = x.f.f/SZ;
int _y = y.f.f/SZ;
if(_x != _y) return _x < _y;
return x.f.s < y.f.s;
}
void update(int x, int val){
for(; x < MXN ; tree[x] += val, x += x & -x) ;
}
int query(int x){
int sum = 0;
for(; x > 0 ; sum += tree[x], x -= x & -x) ;
return sum;
}
void add(int x){
update(x, 1);
}
void remove(int x){
update(x, -1);
}
int main() {
scanf("%d", &n);
SZ = static_cast<int> (sqrt(n));
vector<int> V;
for(int i = 0; i < n; i++){
scanf("%d", &Arr[i]);
V.push_back(Arr[i]);
}
scanf("%d", &q);
for(int i = 0; i<q; i++){
scanf("%d %d %d", &queries[i].f.f, &queries[i].f.s, &K[i]);
queries[i].f.f--;
queries[i].f.s--;
queries[i].s = i;
V.push_back(K[i]);
}
sort(queries, queries + q, cmp);
sort(V.begin(), V.end());
//V.resize(unique(V.begin(), V.end()) - V.begin());
for(int i = 0; i<n; i++){
int val = upper_bound(V.begin(), V.end(), Arr[i]) - V.begin();
Arr[i] = val;
}
for(int i = 0; i<q; i++){
int val = upper_bound(V.begin(), V.end(), K[i]) - V.begin();
K[i] = val;
}
int left = 0, right = -1, val = V.size();
for(int i = 0; i<q; i++){
int l = queries[i].f.f;
int r = queries[i].f.s;
int id = queries[i].s;
while(right < r){
right++;
add(Arr[right]);
}
while(right > r){
remove(Arr[right]);
right--;
}
while(left < l){
remove(Arr[left]);
left++;
}
while(left > l){
left--;
add(Arr[left]);
}
Ans[id] = query(val) - query(K[id]);
}
for(int i = 0; i<q; i++) printf("%d\n", Ans[i]);
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpjb25zdCBpbnQgTVggPS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