#include <bits/stdc++.h>
using namespace std;
namespace IO {
template <typename T>
inline void read(T &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  x *= f;
  return;
}
template <typename T>
inline void write(T x = 0) {
  T wr[51];
  wr[0] = 0;
  if (x < 0) putchar('-'), x = -x;
  if (!x) putchar(48);
  while (x) wr[++wr[0]] = x % 10, x /= 10;
  while (wr[0]) putchar(48 + wr[wr[0]--]);
  return;
}
}  // namespace IO
using IO::read;
using IO::write;
const int N = 1e5 + 11, G = 321;
int n, m, op, l, r, x, pos, ans;
int id[N], f[N], cnt[N], val[N], mx[N];
int a[G][N], b[N], tag[G];
inline void merge(int x, int y) { f[y] = x, cnt[x] += cnt[y]; }
inline int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
inline void cg1(int l, int r, int x) {
  for (pos = l; id[pos - 1] == id[l]; --pos)
    ;
  for (register int i = pos; id[i] == id[r]; ++i) {
    b[i] = val[find(i)], a[id[i]][val[i]] = 0;
  }
  mx[id[r]] = 0;
  for (register int i = l; i <= r; ++i)
    if (b[i] - tag[id[i]] > x) b[i] -= x;
  for (register int i = pos; id[i] == id[r]; ++i) {
    f[i] = i, val[i] = b[i], cnt[i] = 1;
    mx[id[i]] = max(mx[id[i]], val[i]);
    if (!a[id[i]][val[i]])
      a[id[i]][val[i]] = i;
    else
      merge(a[id[i]][val[i]], i);
  }
}
inline void cg2(int l, int r, int x) {
  if (l > r) return;
  for (register int i, j = l; j <= r; ++j)
    if (tag[j] + x < mx[j]) {
      if (tag[j] + x + x <= mx[j]) {
        for (i = tag[j] + x; i > tag[j]; --i)
          if (a[j][i]) {
            if (!a[j][i + x])
              val[a[j][i + x] = a[j][i]] = i + x;
            else
              merge(a[j][i + x], a[j][i]);
            a[j][i] = 0;
          }
        tag[j] += x;
      } else {
        for (i = tag[j] + x + 1; i <= mx[j]; ++i)
          if (a[j][i]) {
            if (!a[j][i - x])
              val[a[j][i - x] = a[j][i]] = i - x;
            else
              merge(a[j][i - x], a[j][i]);
            a[j][i] = 0;
          }
        for (i = tag[j] + x; !a[j][i]; --i)
          ;
        mx[j] = i;
      }
    }
}
int main() {
  read(n), read(m);
  for (register int i = 1; i <= n; ++i) {
    id[i] = i / G, f[i] = i, cnt[i] = 1, read(val[i]),
    mx[id[i]] = max(mx[id[i]], val[i]);
    if (!a[id[i]][val[i]])
      a[id[i]][val[i]] = i;
    else
      merge(a[id[i]][val[i]], i);
  }
  id[0] = id[n + 1] = -1;
  while (m--) {
    read(op), read(l), read(r), read(x);
    if (op == 1) {
      if (id[l] == id[r]) {
        cg1(l, r, x);
        continue;
      }
      for (pos = l; id[pos + 1] == id[l]; ++pos)
        ;
      cg1(l, pos, x);
      for (pos = r; id[pos - 1] == id[r]; --pos)
        ;
      cg1(pos, r, x);
      cg2(id[l] + 1, id[r] - 1, x);
    } else {
      ans = 0;
      if (id[l] == id[r])
        for (register int i = l; i <= r; ++i)
          ans += (val[find(i)] - tag[id[i]] == x);
      else {
        for (pos = l; id[pos] == id[l]; ++pos)
          ans += (val[find(pos)] - tag[id[pos]] == x);
        for (pos = r; id[pos] == id[r]; --pos)
          ans += (val[find(pos)] - tag[id[pos]] == x);
        for (register int i = id[l] + 1; i <= id[r] - 1; ++i)
          if (x + tag[i] < N) ans += cnt[a[i][x + tag[i]]];
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
