#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx")
using namespace std;
inline int read_char() {
  static char buf[1 << 16], *ptr = buf, *end_ptr = buf;
  if (ptr == end_ptr) {
    int len = fread(buf, 1, sizeof(buf), stdin);
    if (len <= 0) return EOF;
    ptr = buf;
    end_ptr = buf + len;
  }
  return *ptr++;
}
inline int read_int() {
  int sg = +1, ch;
  do {
    ch = read_char();
    if (ch == '-') sg = -1;
  } while (ch < '0' || ch > '9');
  int first = ch - '0';
  while (true) {
    ch = read_char();
    if (ch < '0' || ch > '9') break;
    first = first * 10 + ch - '0';
  }
  return sg * first;
}
void _R(int &first) { first = read_int(); }
void R() {}
template <class T, class... U>
void R(T &head, U &...tail) {
  _R(head);
  R(tail...);
}
template <class T>
void _W(const T &first) {
  cout << first;
}
void _W(const int &first) { printf("%d", first); }
void _W(const int64_t &first) { printf("%" PRId64, first); }
void _W(const double &first) { printf("%.16f", first); }
void _W(const char &first) { putchar(first); }
void _W(const char *first) { printf("%s", first); }
template <class T>
void _W(const vector<T> &first) {
  for (auto i = first.begin(); i != first.end(); _W(*i++))
    if (i != first.cbegin()) putchar(' ');
}
void W() {}
template <class T, class... U>
void W(const T &head, const U &...tail) {
  _W(head);
  putchar(sizeof...(tail) ? ' ' : '\n');
  W(tail...);
}
float arr[100005];
int main() {
  int n, m;
  R(n, m);
  for (int i = 1; i <= n; i++) arr[i] = read_int();
  while (m--) {
    int t, l, r;
    R(t, l, r);
    float first = read_int();
    if (t == 1) {
      for (int i = l; i <= r; i++)
        if (arr[i] > first) arr[i] -= first;
    } else {
      int ans = 0;
      for (int i = l; i <= r; i++)
        if (arr[i] == first) ans++;
      W(ans);
    }
  }
}
