#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, M = 250 + 2, M2 = 400 + 3;
inline int read() {
  int sum;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  sum = c - '0';
  c = getchar();
  while (c >= '0' && c <= '9') {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  return sum;
}
inline void write(int x) {
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
int fk[M][M2], bj[M] = {0}, fkfa[M][M2], im[M] = {0};
int bcj[M][N], siz[M][N];
int n, m, n2;
int zks, wks;
void jbj(int o, int y) {
  int imax = im[o], x = bj[o];
  if (2 * y < imax - x) {
    for (int i = x + 1; i <= x + y; ++i) {
      if (!bcj[o][i]) continue;
      int z = i + y;
      if (!bcj[o][z]) {
        bcj[o][z] = bcj[o][i];
        fk[o][bcj[o][i]] = z;
        siz[o][z] += siz[o][i];
        bcj[o][i] = 0;
        siz[o][i] = 0;
      } else {
        if (bcj[o][i] > bcj[o][z]) {
          fkfa[o][bcj[o][i]] = bcj[o][z];
          siz[o][z] += siz[o][i];
          bcj[o][i] = 0;
          siz[o][i] = 0;
        } else {
          fkfa[o][bcj[o][z]] = bcj[o][i], fk[o][bcj[o][i]] = z;
          bcj[o][z] = bcj[o][i];
          siz[o][z] += siz[o][i];
          bcj[o][i] = 0;
          siz[o][i] = 0;
        }
      }
    }
    bj[o] += y;
  } else {
    int imax2 = 0;
    for (int i = x + y + 1; i <= imax; ++i) {
      if (!bcj[o][i]) continue;
      int z = i - y;
      if (!bcj[o][z]) {
        bcj[o][z] = bcj[o][i];
        fk[o][bcj[o][i]] = z;
        siz[o][z] += siz[o][i];
        bcj[o][i] = 0;
        siz[o][i] = 0;
      } else {
        if (bcj[o][i] > bcj[o][z]) {
          fkfa[o][bcj[o][i]] = bcj[o][z];
          siz[o][z] += siz[o][i];
          bcj[o][i] = 0;
          siz[o][i] = 0;
        } else {
          fkfa[o][bcj[o][z]] = bcj[o][i], fk[o][bcj[o][i]] = z;
          bcj[o][z] = bcj[o][i];
          siz[o][z] += siz[o][i];
          bcj[o][i] = 0;
          siz[o][i] = 0;
        }
      }
    }
    im[o] = min(im[o], x + y);
  }
}
void reb(int o) {
  int zs = o == zks ? wks : n2;
  for (int i = 1; i <= zs; ++i) bcj[o][fk[o][i]] = 0, siz[o][fk[o][i]] = 0;
  im[o] = 0;
  bj[o] = 0;
  for (int i = 1; i <= zs; ++i) {
    int x = fk[o][i];
    im[o] = max(im[o], x);
    if (!bcj[o][x]) {
      fkfa[o][i] = i;
      bcj[o][x] = i;
    } else {
      fkfa[o][i] = bcj[o][x];
    }
    ++siz[o][x];
  }
}
int fifa(int o, int x) {
  return fkfa[o][x] == x ? x : fkfa[o][x] = fifa(o, fkfa[o][x]);
}
void pushdown(int o) {
  int zs = o == zks ? wks : n2;
  int pbj = bj[o];
  for (int i = zs; i > 0; --i) {
    int fa = fifa(o, i);
    int x = fk[o][fa];
    if (fa == i) bcj[o][x] = 0, siz[o][x] = 0;
    if (x > pbj)
      fk[o][i] = x - pbj;
    else
      fk[o][i] = x;
  }
  bj[o] = 0;
}
int cx(int o, int l, int r, int x) {
  pushdown(o);
  reb(o);
  int ans = 0;
  for (int i = l; i <= r; ++i) {
    if (fk[o][i] == x) {
      ++ans;
    }
  }
  return ans;
}
int cx2(int o, int x) {
  int pbj = bj[o], imax = im[o];
  int ans = 0;
  if (pbj >= x) {
    ans = x > imax ? 0 : siz[o][x];
  }
  if (pbj + x <= imax) {
    ans += siz[o][pbj + x];
  }
  return ans;
}
void xg(int o, int l, int r, int x) {
  pushdown(o);
  for (int i = l; i <= r; ++i) {
    if (fk[o][i] > x) {
      fk[o][i] -= x;
    }
  }
  reb(o);
}
void xg2(int o, int x) { jbj(o, x); }
int main() {
  cin >> n >> m;
  n2 = 400;
  zks = (n - 1) / n2;
  wks = (n - 1) % n2 + 1;
  for (int i = 0; i < n; i++) {
    int i2 = i / n2, i3 = i % n2 + 1;
    int x = read();
    fk[i2][i3] = x;
    im[i2] = max(im[i2], x);
    if (!bcj[i2][x]) {
      fkfa[i2][i3] = i3;
      bcj[i2][x] = i3;
    } else {
      fkfa[i2][i3] = bcj[i2][x];
    }
    ++siz[i2][x];
  }
  while (m) {
    --m;
    int t = read(), l = read(), r = read(), x = read();
    --l, --r;
    int ll = l / n2, rr = r / n2;
    if (t == 1) {
      if (ll == rr)
        xg(ll, l % n2 + 1, r % n2 + 1, x);
      else {
        xg(ll, l % n2 + 1, n2, x);
        xg(rr, 1, r % n2 + 1, x);
        for (int i = ll + 1; i <= rr - 1; ++i) xg2(i, x);
      }
    } else {
      int ans = 0;
      if (ll == rr)
        ans = cx(ll, l % n2 + 1, r % n2 + 1, x);
      else {
        ans = cx(ll, l % n2 + 1, n2, x) + cx(rr, 1, r % n2 + 1, x);
        for (int i = ll + 1; i <= rr - 1; ++i) ans += cx2(i, x);
      }
      write(ans);
      putchar('\n');
    }
  }
}
