#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx")
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
using namespace std;
namespace {
namespace shik {
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 x = ch - '0';
  while (true) {
    ch = read_char();
    if (ch < '0' || ch > '9') break;
    x = x * 10 + ch - '0';
  }
  return sg * x;
}
template <class T>
void _W(const T &x) {
  cout << x;
}
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%" PRId64, x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template <class T>
void _W(const vector<T> &x) {
  for (auto i = x.begin(); i != x.end(); _W(*i++))
    if (i != x.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...);
}
const int N = 1e5 + 10;
int n, m;
float __attribute__((aligned(32))) a[N];
void main() {
  n = read_int();
  m = read_int();
  for (int i = 1; i <= n; i++) a[i] = read_int();
  while (m--) {
    int op, l, r, x;
    op = read_int();
    l = read_int();
    r = read_int();
    x = read_int();
    if (op == 1) {
      for (int i = l; i <= r; i++)
        if (a[i] > x) a[i] -= x;
    } else {
      int ans = 0;
      for (int i = l; i <= r; i++)
        if (a[i] == x) ans++;
      W(ans);
    }
  }
}
}  // namespace shik
}  // namespace
int main() {
  shik::main();
  return 0;
}
