#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char ch = getchar();
  int nega = 1;
  while (!isdigit(ch)) {
    if (ch == '-') nega = -1;
    ch = getchar();
  }
  int ans = 0;
  while (isdigit(ch)) {
    ans = ans * 10 + ch - 48;
    ch = getchar();
  }
  if (nega == -1) return -ans;
  return ans;
}
int add(int x, int y) { return x + y >= 998244353 ? x + y - 998244353 : x + y; }
int sub(int x, int y) { return x - y < 0 ? x - y + 998244353 : x - y; }
int mul(int x, int y) { return 1LL * x * y % 998244353; }
int B = 707;
int n, m, a[500005], b[500005], fa[500005];
int c[500005], d[500005];
struct Query {
  int opt, l, r, x, ans;
};
Query q[500005];
int find(int u) { return u == fa[u] ? u : fa[u] = find(fa[u]); }
void merge(int x, int y) {
  if (c[y])
    fa[c[x]] = c[y];
  else {
    b[c[x]] = y;
    c[y] = c[x];
  }
  d[y] += d[x];
  c[x] = d[x] = 0;
}
signed main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) a[i] = read();
  for (int i = 1; i <= m; i++) {
    q[i].opt = read(), q[i].l = read(), q[i].r = read(), q[i].x = read();
  }
  for (int L = 1, R = B; L <= n; L += B, R += B) {
    if (R > n) R = n;
    if (L > n) break;
    int maxn = 0, tag = 0;
    for (int k = 1; k <= 500000; k++) {
      if (c[k]) c[k] = 0;
      if (d[k]) d[k] = 0;
    }
    for (int k = L; k <= R; k++) {
      if (a[k] > maxn) maxn = a[k];
      int x = a[k];
      if (c[x])
        fa[k] = c[x];
      else {
        c[x] = fa[k] = k;
        b[k] = x;
      }
      d[x]++;
    }
    for (int j = 1; j <= m; j++) {
      int opt = q[j].opt, l = q[j].l, r = q[j].r, x = q[j].x;
      if (r < L || l > R) continue;
      if (opt == 1) {
        if (l <= L && R <= r) {
          if (x * 2 <= maxn - tag) {
            for (int k = tag + 1; k <= tag + x; k++) {
              if (c[k]) merge(k, k + x);
            }
            tag += x;
          } else {
            for (int k = maxn; k > tag + x; k--) {
              if (c[k]) merge(k, k - x);
            }
            maxn = min(maxn, tag + x);
          }
        } else {
          for (int k = L; k <= R; k++) {
            a[k] = b[find(k)];
            c[a[k]] = d[a[k]] = 0;
            a[k] -= tag;
          }
          memset(b + L, 0, (R - L + 1) * 4);
          tag = 0;
          l = max(l, L), r = min(r, R);
          for (int k = l; k <= r; k++)
            if (a[k] > x) a[k] -= x;
          maxn = 0;
          for (int k = L; k <= R; k++) {
            if (a[k] > maxn) maxn = a[k];
            int x = a[k];
            if (c[x])
              fa[k] = c[x];
            else {
              c[x] = fa[k] = k;
              b[k] = x;
            }
            d[x]++;
          }
        }
      }
      if (opt == 2) {
        if (l <= L && R <= r) {
          if (x + tag <= 500000) q[j].ans += d[x + tag];
        } else {
          l = max(l, L), r = min(r, R);
          for (int k = l; k <= r; k++) {
            if (b[find(k)] == tag + x) q[j].ans++;
          }
        }
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    if (q[i].opt == 2) printf("%d\n", q[i].ans);
  }
  return 0;
}
