#include <bits/stdc++.h>
using namespace std;
const int N = 100005, B = 320;
int n, m, blo, cnt, a[N], b[N], pos[N], l[B], r[B], laz[B], ma[B], fa[N],
    rt[B][N], num[N];
inline int Find(int x) {
  while (x != fa[x]) x = fa[x] = fa[fa[x]];
  return x;
}
inline void pre(int x) {
  int i;
  ma[x] = laz[x] = 0;
  for (i = l[x]; i <= r[x]; i++) {
    ma[x] = max(ma[x], a[i]);
    num[i] = 1;
    if (rt[x][a[i]]) {
      fa[i] = rt[x][a[i]];
      num[rt[x][a[i]]]++;
    } else {
      rt[x][a[i]] = i;
      fa[i] = i;
      b[i] = a[i];
    }
  }
}
inline void del(int x) {
  int i;
  for (i = l[x]; i <= r[x]; i++)
    a[i] = b[Find(i)], rt[x][a[i]] = 0, a[i] -= laz[x];
  for (i = l[x]; i <= r[x]; i++) fa[i] = 0;
  laz[x] = 0;
}
inline void cha(int x, int aa, int bb) {
  if (rt[x][bb])
    fa[rt[x][aa]] = rt[x][bb], num[rt[x][bb]] += num[rt[x][aa]];
  else
    rt[x][bb] = rt[x][aa], b[rt[x][aa]] = bb;
  rt[x][aa] = 0;
}
inline void ins(int x, int y, int z) {
  int i, j;
  if (pos[x] == pos[y]) {
    del(pos[x]);
    for (i = x; i <= y; i++)
      if (a[i] > z) a[i] -= z;
    pre(pos[x]);
  } else {
    for (i = pos[x] + 1; i < pos[y]; i++) {
      if (ma[i] - laz[i] >= z * 2) {
        for (j = laz[i] + 1; j <= laz[i] + z; j++)
          if (rt[i][j]) cha(i, j, j + z);
        laz[i] += z;
      } else {
        for (j = laz[i] + z + 1; j <= ma[i]; j++)
          if (rt[i][j]) cha(i, j, j - z);
        ma[i] = min(ma[i], laz[i] + z);
      }
    }
    del(pos[y]);
    del(pos[x]);
    for (i = x; i <= r[pos[x]]; i++)
      if (a[i] > z) a[i] -= z;
    for (i = l[pos[y]]; i <= y; i++)
      if (a[i] > z) a[i] -= z;
    pre(pos[x]);
    pre(pos[y]);
  }
  return;
}
inline int que(int x, int y, int z) {
  int i, re = 0;
  if (pos[x] == pos[y]) {
    for (i = x; i <= y; i++)
      if (b[Find(i)] == z + laz[pos[x]]) re++;
  } else {
    for (i = x; i <= r[pos[x]]; i++) re += (b[Find(i)] == z + laz[pos[x]]);
    for (i = pos[x] + 1; i < pos[y]; i++)
      if (z + laz[i] < N) re += num[rt[i][z + laz[i]]];
    for (i = l[pos[y]]; i <= y; i++) re += (b[Find(i)] == z + laz[pos[y]]);
  }
  return re;
}
int main() {
  int i, op, x, y, z;
  scanf("%d%d", &n, &m);
  blo = sqrt(n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]), pos[i] = (i - 1) / blo + 1;
  cnt = n / blo + (bool)(n % blo);
  for (i = 1; i <= cnt; i++) l[i] = (i - 1) * blo + 1, r[i] = i * blo;
  r[cnt] = n;
  for (i = 1; i <= cnt; i++) pre(i);
  for (i = 1; i <= m; i++) {
    scanf("%d%d%d%d", &op, &x, &y, &z);
    if (op == 1)
      ins(x, y, z);
    else if (op == 2)
      printf("%d\n", que(x, y, z));
  }
}
