#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n, m, a[N], tree[N], ans[N];
struct QUERY
{
int l, r, h, no;
} query[N];
struct number
{
int h, no;
} numbers[N];
int lowbit(int x)
{
return x & (-x);
}
void add(int i)
{
while (i <= n)
{
tree[i]++;
i += lowbit(i);
}
}
bool cmp1(number a, number b)
{
return a.h > b.h;
}
bool cmp2(QUERY a, QUERY b)
{
return a.h > b.h;
}
int sum(int i)
{
int ans = 0;
while (i > 0)
{
ans += tree[i];
i -= lowbit(i);
}
return ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
cin >> numbers[i].h;
numbers[i].no = i;
}
for (int i = 1; i <= m; i++)
{
cin >> query[i].l >> query[i].r >> query[i].h;
query[i].no = i;
}
sort(numbers + 1, numbers + n + 1, cmp1);
sort(query + 1, query + m + 1, cmp2);
int id = 1;
for (int i = 1; i <= m; i++)
{
while (numbers[id].h >= query[i].h && id <= n)
{
add(numbers[id].no);
id++;
}
ans[query[i].no] = sum(query[i].r) - sum(query[i].l - 1);
}
for (int i = 1; i <= m; i++)
{
cout << ans[i] << endl;
}
return 0;
}