#include <bits/stdc++.h>
#define ll long long
#define MAXN 200010
#define D 450

using namespace std;

struct Query
{
	ll vred;
	pair <ll, ll> udalj;
	ll idx;
};

map <ll, ll> broji;
vector <ll> niz(MAXN);
vector <ll> rez(MAXN);
vector <Query> sve(MAXN);

bool cmp(Query A, Query B)
{
	A.udalj.first /= D;
	B.udalj.first /= D;
	return A.udalj < B.udalj;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int N, Q, L, R, X, Y, ima = 0;
    cin >> N >> Q;
    if(N <= 1010 && Q <= 1010)
    {
        vector <pair<int, int> > A(N);
        for(int i = 0; i < N; i++) {cin >> X >> Y; A[i] = {X, Y};}
        while(Q--)
        {
            ima = 0;
            cin >> L >> R >> X;
            L--;
            R--;
            for(int i = L; i <= R; i++) {if(X >= A[i].first && X <= A[i].second) ima++;}
            cout << ima << endl;
        }
    }
    else
    {
        for(int i = 0; i < N; i++) {cin >> niz[i];}
        cin >> Q;
        for(int i = 0; i < Q; i++)
        {
            cin >> L >> R >> X;
            sve[i].udalj.first = L - 1;
            sve[i].udalj.second = R - 1;
            sve[i].vred = X;
            sve[i].idx = i;
        }
        sort(sve.begin(), sve.begin() + Q, cmp);
        L = 0, R = -1;
        for(int i = 0; i < Q; i++)
        {
            while(L > sve[i].udalj.first) {L--; broji[niz[L]]++;}
            while(R < sve[i].udalj.second) {R++; broji[niz[R]]++;}
            while(R > sve[i].udalj.second) {broji[niz[R]]--; R--;}
            while(L < sve[i].udalj.first) {broji[niz[L]]--; L++;}
            rez[sve[i].idx] = broji[sve[i].vred];
        }
        for(int i = 0; i < Q; i++) cout << rez[i] << endl;
    }
    return 0;
}
/**
10 5
1 8 6 4 4 3 2 2 1 5
1 5 4
5 6 7
6 10 2
9 9 1
1 10 1
**/