#include <bits/stdc++.h>
using namespace std;
inline char gc() {
  static char buf[100000], *p1, *p2;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline 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 = 100010, K = 1000;
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];
}
void build(int i) {
  for (int j = (i - 1) * K + 1; j <= min(n, i * K); ++j)
    if (pre[col[j]])
      fa[j] = pre[col[j]];
    else
      fa[j] = pre[col[j]] = j;
  for (int j = (i - 1) * K + 1; j <= min(n, i * K); ++j)
    rt[i][col[j]] = pre[col[j]] - (i - 1) * K;
  for (int j = (i - 1) * K + 1; j <= min(n, i * K); ++j)
    siz[j] = pre[col[j]] = 0;
  for (int j = (i - 1) * K + 1; j <= min(n, i * K); ++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 t = 1; t <= q; ++t) {
    int typ = rd(), l = rd(), r = rd(), x = rd();
    if (typ == 1) {
      for (int j = (bl[l] - 1) * K + 1; j <= min(n, bl[l] * K); ++j)
        col[j] = col[find(j)];
      for (int j = (bl[l] - 1) * K + 1; j <= min(n, bl[l] * K); ++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]) {
        for (int j = (bl[r] - 1) * K + 1; j <= min(n, bl[r] * K); ++j)
          col[j] = col[find(j)];
        for (int j = (bl[r] - 1) * K + 1; j <= min(n, bl[r] * K); ++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;
      for (int j = (bl[l] - 1) * K + 1; j <= min(n, bl[l] * K); ++j)
        col[j] = col[find(j)];
      for (int j = (bl[l] - 1) * K + 1; j <= min(n, bl[l] * K); ++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]) {
        for (int j = (bl[r] - 1) * K + 1; j <= min(n, bl[r] * K); ++j)
          col[j] = col[find(j)];
        for (int j = (bl[r] - 1) * K + 1; j <= min(n, bl[r] * K); ++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;
}
