#include <bits/stdc++.h>
using namespace std;
inline char gc() {
  static char buf[1 << 16], *p1, *p2;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 16, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
int rd() {
  int x = 0;
  char c = gc();
  for (; c < 48 || c > 57; c = gc())
    ;
  for (; c > 47 && c < 58; x = x * 10 + c - 48, c = gc())
    ;
  return x;
}
const int mxn = 131072, K = 400;
int n, q, bl[mxn], fa[mxn], col[mxn], pre[mxn], mx[mxn], tag[mxn];
short rt[512][mxn], siz[mxn];
int find(int x) {
  if (fa[x] != x) fa[x] = find(fa[x]);
  return fa[x];
}
inline void build(int i) {
  int x = (i - 1) * K + 1, y = min(n, i * K);
  for (int j = x; j <= y; ++j)
    if (pre[col[j]])
      fa[j] = pre[col[j]];
    else
      fa[j] = pre[col[j]] = j;
  for (int j = x; j <= y; ++j) rt[i][col[j]] = pre[col[j]] - (i - 1) * K;
  for (int j = x; j <= y; ++j) siz[j] = pre[col[j]] = 0;
  for (int j = x; j <= y; ++j) ++siz[fa[j]], mx[i] = max(mx[i], col[j]);
}
int main() {
  n = rd(), q = rd();
  for (int i = 1; i <= n; ++i) bl[i] = (i - 1) / K + 1;
  for (int i = 1; i <= n; ++i) col[i] = rd();
  for (int i = 1; i <= bl[n]; ++i) build(i);
  for (int typ, st, ed, l, r, x, t = 1; t <= q; ++t) {
    typ = rd(), l = rd(), r = rd(), x = rd();
    if (typ == 1) {
      st = (bl[l] - 1) * K + 1;
      ed = min(n, bl[l] * K);
      for (int j = st; j <= ed; ++j) col[j] = col[find(j)];
      for (int j = st; j <= ed; ++j) {
        rt[bl[l]][col[j]] = 0, col[j] -= tag[bl[l]];
        if (l <= j && j <= r && col[j] > x) col[j] -= x;
      }
      tag[bl[l]] = 0;
      build(bl[l]);
      if (bl[l] != bl[r]) {
        st = (bl[r] - 1) * K + 1;
        ed = min(n, bl[r] * K);
        for (int j = st; j <= ed; ++j) col[j] = col[find(j)];
        for (int j = st; j <= ed; ++j) {
          rt[bl[r]][col[j]] = 0, col[j] -= tag[bl[r]];
          if (l <= j && j <= r && col[j] > x) col[j] -= x;
        }
        tag[bl[r]] = 0;
        build(bl[r]);
      }
      for (int i = bl[l] + 1; i < bl[r]; ++i)
        if (mx[i] - tag[i] > 2 * x) {
          for (int j = tag[i] + 1; j <= tag[i] + x; ++j)
            if (rt[i][j]) {
              if (rt[i][j + x])
                siz[rt[i][j] + (i - 1) * K] += siz[rt[i][j + x] + (i - 1) * K],
                    fa[rt[i][j + x] + (i - 1) * K] = rt[i][j] + (i - 1) * K;
              col[rt[i][j] + (i - 1) * K] = j + x;
              rt[i][j + x] = rt[i][j];
              rt[i][j] = 0;
            }
          tag[i] += x;
        } else if (mx[i] - tag[i] > x) {
          for (int j = tag[i] + x + 1; j <= mx[i]; ++j)
            if (rt[i][j]) {
              if (rt[i][j - x])
                siz[rt[i][j] + (i - 1) * K] += siz[rt[i][j - x] + (i - 1) * K],
                    fa[rt[i][j - x] + (i - 1) * K] = rt[i][j] + (i - 1) * K;
              col[rt[i][j] + (i - 1) * K] = j - x;
              rt[i][j - x] = rt[i][j];
              rt[i][j] = 0;
            }
          mx[i] = tag[i] + x;
        }
    } else {
      int ans = 0;
      st = (bl[l] - 1) * K + 1;
      ed = min(n, bl[l] * K);
      for (int j = st; j <= ed; ++j) col[j] = col[find(j)];
      for (int j = st; j <= ed; ++j) {
        rt[bl[l]][col[j]] = 0, col[j] -= tag[bl[l]];
        if (l <= j && j <= r) ans += col[j] == x;
      }
      tag[bl[l]] = 0;
      build(bl[l]);
      if (bl[l] != bl[r]) {
        st = (bl[r] - 1) * K + 1;
        ed = min(n, bl[r] * K);
        for (int j = st; j <= ed; ++j) col[j] = col[find(j)];
        for (int j = st; j <= ed; ++j) {
          rt[bl[r]][col[j]] = 0, col[j] -= tag[bl[r]];
          if (l <= j && j <= r) ans += col[j] == x;
        }
        tag[bl[r]] = 0;
        build(bl[r]);
      }
      for (int i = bl[l] + 1; i < bl[r]; ++i)
        if (x + tag[i] <= mx[i] && rt[i][x + tag[i]])
          ans += siz[rt[i][x + tag[i]] + (i - 1) * K];
      printf("%d\n", ans);
    }
  }
  return 0;
}
