/* Rozwiazanie wzorcowe do zadania MRO (Mrowki)
 * Autor: Jakub Radoszewski
 * Opis: dwukolorowanie grafu.
*/

#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;

int n, q;
map<int, int> mrowki;

int main() {
  scanf("%d%d", &n, &q);
  for (int i = 0; i < n; ++i) {
    int a;
    scanf("%d", &a);
    ++mrowki[a];
  }
  while (q--) {
    int l, r, d;
    scanf("%d%d%d", &l, &r, &d);
    int wynik = 0, suma = 0;
    if (mrowki.find(d) != mrowki.end()) wynik = -mrowki[d];
    map<int, int>::iterator it;
    while (1) {
      it = mrowki.lower_bound(l);
      if (it != mrowki.end() && it->first <= r) {
        wynik += it->second;
        suma += it->second;
        mrowki.erase(it);
      } else break;
    }
    mrowki[d] = suma;
    printf("%d\n", wynik);
  }
  return 0;
}
