#include <bits/stdc++.h>
char buf[1 << 25], *O = buf;
inline void pri(int x) {
  register char out[11], *p = out;
  if (x < 0) x = -x, *O++ = 45;
  if (x) {
    for (; x; x /= 10) *p++ = x % 10 | 48;
    while (p-- != out) *O++ = *p;
  } else
    *O++ = 48;
  *O++ = 10;
}
inline int read() {
  register int re = 0, f = 1;
  register char c;
  while (c = getchar(), ((c) > 47 && (c) < 58) ^ 1) f = c ^ 45;
  while (re = (re << 1) + (re << 3) + (c ^ 48), c = getchar(),
         ((c) > 47 && (c) < 58))
    ;
  return f ? re : -re;
}
const int maxn = 100003, maxm = 323, INF = 0x3f3f3f3f;
int n, sz, m;
int f[maxm][maxn], s[maxn], prt[maxn];
int bl[maxn], a[maxn], sub[maxm], v[maxn], mx[maxm];
struct liu {
  int l, r;
} bb[maxm];
inline int Getfa(int x) { return prt[x] == 0 ? x : prt[x] = Getfa(prt[x]); }
void Rebuild(int x) {
  int l = bb[x].l, r = bb[x].r;
  for (int i = (l); i <= (r); ++i) a[i] = v[Getfa(i)], f[x][a[i]] = 0;
  memset(prt + l, 0, r - l + 1 << 2);
  for (int i = (l); i <= (r); ++i) {
    if (f[x][a[i]])
      s[f[x][a[i]]] += s[i], prt[i] = f[x][a[i]];
    else
      f[x][a[i]] = i, v[i] = a[i], s[i] = 1;
  }
  while (!f[x][mx[x]]) --mx[x];
}
void Solve(int x, int l, int r, int num) {
  int L = bb[x].l, R = bb[x].r;
  for (int i = (L); i <= (R); ++i) a[i] = v[Getfa(i)], f[x][a[i]] = 0;
  for (int i = (l); i <= (r); ++i)
    if (a[i] - sub[x] > num) a[i] -= num;
  for (int i = (L); i <= (R); ++i) v[i] = a[i], prt[i] = 0;
  Rebuild(x);
}
void Chg(int l, int r, int x) {
  int L = bl[l], R = bl[r];
  if (L == R)
    Solve(L, l, r, x);
  else {
    Solve(L, l, bb[L].r, x);
    for (int i = (L + 1); i <= (R - 1); ++i) {
      if (x * 2 <= mx[i] - sub[i]) {
        for (int j = (sub[i] + 1); j <= (sub[i] + x); ++j)
          if (f[i][j]) {
            if (!f[i][j + x])
              f[i][j + x] = f[i][j], v[f[i][j]] = j + x, f[i][j] = 0;
            else
              s[f[i][j + x]] += s[f[i][j]], prt[f[i][j]] = f[i][j + x],
                                            f[i][j] = 0;
          }
        sub[i] += x;
      } else {
        for (int j = (x + sub[i] + 1); j <= (mx[i]); ++j)
          if (f[i][j]) {
            if (!f[i][j - x])
              f[i][j - x] = f[i][j], v[f[i][j]] = j - x, f[i][j] = 0;
            else
              s[f[i][j - x]] += s[f[i][j]], prt[f[i][j]] = f[i][j - x],
                                            f[i][j] = 0;
          }
        while (!f[i][mx[i]]) --mx[i];
      }
    }
    Solve(R, bb[R].l, r, x);
  }
}
int Que(int l, int r, int x) {
  int L = bl[l], R = bl[r], ans = 0;
  if (L == R) {
    for (int i = (l); i <= (r); ++i)
      if (v[Getfa(i)] - sub[L] == x) ++ans;
  } else {
    for (int i = (l); i <= (bb[L].r); ++i)
      if (v[Getfa(i)] - sub[L] == x) ++ans;
    for (int i = (L + 1); i <= (R - 1); ++i)
      if (x + sub[i] <= 100000) ans += s[f[i][x + sub[i]]];
    for (int i = (bb[R].l); i <= (r); ++i)
      if (v[Getfa(i)] - sub[R] == x) ++ans;
  }
  return ans;
}
int main() {
  n = read(), m = read();
  sz = sqrt(n);
  for (int i = (1); i <= (n); ++i) v[i] = read(), bl[i] = (i - 1) / sz + 1;
  for (int i = (1); i <= (bl[n]); ++i)
    bb[i] = (liu){bb[i - 1].r + 1, bb[i - 1].r + sz};
  bb[bl[n]].r = n;
  for (int x = (1); x <= (bl[n]); ++x) {
    int l = bb[x].l, r = bb[x].r;
    for (int i = (l); i <= (r); ++i) {
      (mx[x]) = std::max((mx[x]), (v[i]));
      if (f[x][v[i]])
        prt[i] = f[x][v[i]], ++s[f[x][v[i]]];
      else
        f[x][v[i]] = i, s[f[x][v[i]]] = 1;
    }
  }
  while (m--) {
    int op = read(), l = read(), r = read(), x = read();
    if (op & 1)
      Chg(l, r, x);
    else
      pri(Que(l, r, x));
  }
  fwrite(buf, 1, O - buf, stdout);
  return 0;
}
