#include <bits/stdc++.h>
using namespace std;
const int S = 325;
const int N = 1e5 + 10;
int n, m, bok, a[N], L[N], R[N], sz[N], fa[N], blk[N], tag[N], mvp[N], val[N],
    c[S][N];
template <class T>
inline void in(T &x) {
  x = 0;
  int f = 0;
  char ch = getchar();
  for (; ch < '0' || ch > '9';) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  for (; ch >= '0' && ch <= '9';) x = x * 10 + ch - '0', ch = getchar();
  x = f ? -x : x;
}
inline int find(int x) { return x == fa[x] ? x : find(fa[x]); }
inline void build(int id) {
  int l = L[id], r = R[id];
  for (int i = l; i <= r; ++i) a[i] = val[find(i)], c[id][a[i]] = 0;
  for (int i = l; i <= r; ++i) fa[i] = i, sz[i] = 1;
  for (int i = l; i <= r; ++i)
    if (c[id][a[i]])
      sz[c[id][a[i]]] += sz[i], fa[i] = c[id][a[i]];
    else
      c[id][a[i]] = i, val[i] = a[i];
  for (; !c[id][mvp[id]]; --mvp[id])
    ;
}
inline void modify(int id, int l, int r, int x) {
  for (int i = L[id]; i <= R[id]; ++i) a[i] = val[find(i)];
  for (int i = L[id]; i <= R[id]; ++i) c[id][a[i]] = 0;
  for (int i = l; i <= r; ++i)
    if (a[i] - tag[id] > x) a[i] -= x;
  for (int i = L[id]; i <= R[id]; ++i) val[i] = a[i], fa[i] = i;
  build(id);
}
inline void update(int l, int r, int x) {
  if (blk[l] == blk[r]) {
    modify(blk[l], l, r, x);
    return;
  }
  modify(blk[l], l, R[blk[l]], x);
  modify(blk[r], L[blk[r]], r, x);
  for (int i = blk[l] + 1; i < blk[r]; ++i)
    if (2 * x <= mvp[i] - tag[i]) {
      for (int j = tag[i] + 1; j <= tag[i] + x; ++j)
        if (c[i][j]) {
          if (!c[i][j + x])
            c[i][j + x] = c[i][j], val[c[i][j]] = j + x, c[i][j] = 0;
          else
            sz[c[i][j + x]] += sz[c[i][j]], fa[c[i][j]] = c[i][j + x],
                                            c[i][j] = 0;
        }
      tag[i] += x;
    } else {
      for (int j = tag[i] + x + 1; j <= mvp[i]; ++j)
        if (c[i][j]) {
          if (!c[i][j - x])
            c[i][j - x] = c[i][j], val[c[i][j]] = j - x, c[i][j] = 0;
          else
            sz[c[i][j - x]] += sz[c[i][j]], fa[c[i][j]] = c[i][j - x],
                                            c[i][j] = 0;
        }
      for (; !c[i][mvp[i]]; --mvp[i])
        ;
    }
}
inline int query(int l, int r, int x) {
  int ret = 0;
  if (blk[l] == blk[r]) {
    for (int i = l; i <= r; ++i) ret += (val[find(i)] - tag[blk[l]] == x);
    return ret;
  }
  for (int i = l; i <= R[blk[l]]; ++i) ret += (val[find(i)] - tag[blk[l]] == x);
  for (int i = L[blk[r]]; i <= r; ++i) ret += (val[find(i)] - tag[blk[r]] == x);
  for (int i = blk[l] + 1; i < blk[r]; ++i)
    if (x + tag[i] <= 100000) ret += sz[c[i][x + tag[i]]];
  return ret;
}
int main() {
  int l, r, x, op;
  in(n), in(m), bok = sqrt(n);
  for (int i = 1; i <= n; ++i) {
    in(val[i]), fa[i] = i;
    blk[i] = (i + bok - 1) / bok, R[blk[i]] = i;
    if (!L[blk[i]]) L[blk[i]] = i;
  }
  for (int i = 1; i <= blk[n]; ++i) mvp[i] = 100000, build(i);
  for (; m--;) {
    in(op), in(l), in(r), in(x);
    if (op & 1)
      update(l, r, x);
    else
      printf("%d\n", query(l, r, x));
  }
  return 0;
}
