#include <bits/stdc++.h>
struct IO {
  IO() {}
  inline char gc() {
    static char buf[100000], *p1 = buf, *p2 = buf;
    return p1 == p2 &&
                   (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
               ? EOF
               : *p1++;
  }
  inline IO& operator>>(int& _) {
    _ = 0;
    bool f = 0;
    char c = gc();
    while (c > '9' || c < '0') f |= (c == '-'), c = gc();
    while (c >= '0' && c <= '9') _ *= 10, _ += c & 15, c = gc();
    _ = f ? -_ : _;
    return *this;
  }
  inline IO& operator<<(int x) {
    if (!x) {
      putchar(48);
      goto f;
    }
    if (x < 0) putchar('-'), x = ~x + 1;
    static short wt[20], len;
    len = 0;
    for (; x; x /= 10) wt[++len] = x % 10;
    while (len) putchar(wt[len--] + 48);
  f:
    putchar('\n');
    return *this;
  }
  inline int operator()() {
    int _ = 0;
    short f = 1;
    char c = gc();
    while (c > '9' || c < '0') f = (c == '-') ? -1 : 1, c = gc();
    while (c >= '0' && c <= '9') _ *= 10, _ += c & 15, c = gc();
    return _ * f;
  }
} io;
int n, m;
int v[100005], a[100005];
int siz, bl[100005];
int L[325], R[325], mx[325];
int fa[100005], stk[100005], top;
inline int find(int x) {
  for (; x ^ fa[x]; x = fa[x]) stk[++top] = x;
  for (; top;) fa[stk[top--]] = x;
  return x;
}
int h[325][100005], tag[325], cnt[100005];
inline void pushup(int id) {
  for (; !h[id][mx[id]]; --mx[id])
    ;
}
inline void build(int id) {
  register int i;
  for (i = L[id]; i <= R[id]; ++i) h[id][i] = 0, cnt[i] = 1;
  for (i = L[id]; i <= R[id]; ++i)
    (h[id][a[i]]) ? cnt[fa[i] = h[id][a[i]]] += cnt[i]
                  : v[h[id][a[i]] = fa[i] = i] = a[i];
  pushup(id);
}
inline void update(int id, int l, int r, int x) {
  register int i;
  for (i = L[id]; i <= R[id]; ++i) h[id][a[i] = v[find(i)]] = 0;
  for (i = l; i <= r; ++i) (a[i] > x + tag[id]) ? a[i] -= x : 0;
  for (i = L[id]; i <= R[id]; ++i) v[fa[i] = i] = a[i];
  build(id);
}
inline int max(int a, int b) { return a > b ? a : b; }
inline void build_block() {
  io >> n >> m;
  siz = sqrt(n);
  register int i;
  for (i = 1; i <= n; ++i)
    bl[fa[i] = i] = (i - 1) / siz + 1,
               mx[bl[i]] = max(mx[bl[i]], v[i] = a[i] = io());
  for (i = 1; i <= bl[n]; ++i) L[i] = R[i - 1] + 1, R[i] = R[i - 1] + siz;
  R[bl[n]] = n;
}
inline void change(int i, int j, int nv) {
  (!h[i][nv]) ? v[h[i][nv] = h[i][j]] = nv
              : cnt[fa[h[i][j]] = h[i][nv]] += cnt[h[i][j]];
  h[i][j] = 0;
}
inline void mdy() {
  int l, r, x;
  io >> l >> r >> x;
  if (bl[l] == bl[r]) return update(bl[l], l, r, x);
  update(bl[l], l, R[bl[l]], x);
  update(bl[r], L[bl[r]], r, x);
  for (register int i = bl[l] + 1, j; i < bl[r]; ++i)
    if ((x << 1) <= mx[i] - tag[i]) {
      for (j = tag[i] + 1; j <= x + tag[i]; ++j)
        if (h[i][j]) change(i, j, j + x);
      tag[i] += x;
    } else {
      for (j = x + tag[i] + 1; j <= mx[i]; ++j)
        if (h[i][j]) change(i, j, j - x);
      pushup(i);
    }
}
inline int qry(int ret = 0) {
  register int l, r, x, i;
  io >> l >> r >> x;
  if (bl[l] == bl[r]) {
    for (i = l; i <= r; ++i) ret += (v[find(i)] - tag[bl[l]] == x);
    return ret;
  }
  for (i = l; i <= R[bl[l]]; ++i) ret += (v[find(i)] - tag[bl[l]] == x);
  for (i = L[bl[r]]; i <= r; ++i) ret += (v[find(i)] - tag[bl[r]] == x);
  for (i = bl[l] + 1; i < bl[r]; ++i)
    (x + tag[i] <= 100000) ? ret += cnt[h[i][x + tag[i]]] : 0;
  return ret;
}
int main() {
  build_block();
  register int i;
  for (i = 1; i <= bl[n]; ++i) build(i);
  for (i = 1; i <= m; ++i) (io() & 1) ? mdy() : void(io << qry());
  return 0;
}
