#include <bits/stdc++.h>
using namespace std;
int B;
int n, m, p, a[1000010], ans[500010], frt[500010], fa[500010], sz[500010],
    re[500010];
struct ask {
  int op, l, r, x;
} q[500010];
int find(int a) { return fa[a] == a ? a : fa[a] = find(fa[a]); }
void merge(int u, int v) {
  if (frt[v]) {
    fa[frt[u]] = frt[v];
  } else
    frt[v] = frt[u], re[frt[v]] = v;
  sz[v] += sz[u];
  re[frt[u]] = 0;
  frt[u] = sz[u] = 0;
}
void work(int L, int R) {
  memset(frt, 0, sizeof(frt));
  memset(fa, 0, sizeof(fa));
  memset(sz, 0, sizeof(sz));
  memset(re, 0, sizeof(re));
  int tag = 0, mx = 0;
  for (int i = L; i <= R; i++) {
    if (!frt[a[i]]) frt[a[i]] = i, re[i] = a[i];
    fa[i] = frt[a[i]], sz[a[i]]++;
    mx = max(mx, a[i]);
  }
  for (int k = 1; k <= m; k++) {
    if (q[k].r < L || q[k].l > R) continue;
    if (q[k].op == 2) {
      if (q[k].x - tag > 500000) continue;
      if (q[k].l <= L && R <= q[k].r) {
        ans[k] += sz[q[k].x - tag];
        continue;
      }
      int l = max(q[k].l, L), r = min(q[k].r, R);
      for (int i = l; i <= r; i++)
        if (re[find(i)] + tag == q[k].x) ans[k]++;
    } else {
      if (q[k].x > mx + tag) continue;
      if (q[k].l <= L && R <= q[k].r) {
        if (q[k].x * 2 <= mx + tag) {
          for (int i = 1; i <= q[k].x; i++) {
            if (frt[i - tag]) merge(i - tag, i + q[k].x - tag);
          }
          tag -= q[k].x;
        } else {
          for (int i = q[k].x + 1; i <= mx + tag; i++) {
            if (frt[i - tag]) merge(i - tag, i - q[k].x - tag);
          }
          mx = min(mx, q[k].x - tag);
        }
        continue;
      }
      for (int i = L; i <= R; i++)
        a[i] = re[find(i)], frt[a[i]] = sz[a[i]] = 0, a[i] += tag;
      for (int i = L; i <= R; i++) re[i] = 0;
      int l = max(q[k].l, L), r = min(q[k].r, R);
      for (int i = l; i <= r; i++)
        if (a[i] > q[k].x) a[i] -= q[k].x;
      tag = 0, mx = 0;
      for (int i = L; i <= R; i++) {
        if (!frt[a[i]]) frt[a[i]] = i, re[i] = a[i];
        fa[i] = frt[a[i]], sz[a[i]]++;
        mx = max(mx, a[i]);
      }
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= m; i++)
    scanf("%d%d%d%d", &q[i].op, &q[i].l, &q[i].r, &q[i].x);
  B = sqrt(n);
  for (int l = 1; l <= n; l += B) work(l, min(l + B - 1, n));
  for (int i = 1; i <= m; i++)
    if (q[i].op == 2) printf("%d\n", ans[i]);
}
