#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const int BSIZ = 650;
namespace block {
int l, r;
int par[100005], siz[100005];
void init() {
  l = 0;
  r = 100000;
  memset(par, -1, sizeof(par));
  memset(siz, 0, sizeof(siz));
}
int root(int x) { return par[x] == -1 ? x : par[x] = root(par[x]); }
void addpar(int u, int v) {
  v = root(v);
  par[u] = v;
  siz[v] += siz[u];
}
void dec(int x) {
  if (r - l >= 2 * x) {
    for (int i = l + 1; i <= l + x; i++) addpar(i, i + x);
    l += x;
  } else if (r - l > x) {
    for (int i = l + x + 1; i <= r; i++) addpar(i, i - x);
    r = l + x;
  }
}
int dec1(int v, int x) {
  v = root(v);
  if (v <= l + x) return v;
  siz[v]--;
  v -= x;
  siz[v]++;
  return v;
}
int query(int x) {
  if (x <= 0 || x > r - l) return 0;
  return siz[l + x];
}
int query1(int x) { return root(x) - l; }
}  // namespace block
int n, q, a[500005];
int qt[500005], ql[500005], qr[500005], qx[500005], qans[500005];
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 0; i < (int)(n); i++) scanf("%d", &a[i]);
  for (int i = 0; i < (int)(q); i++) {
    scanf("%d%d%d%d", &qt[i], &ql[i], &qr[i], &qx[i]);
    ql[i]--;
    qr[i]--;
  }
  for (int i = 0; i < n; i += BSIZ) {
    int j = i + BSIZ - 1;
    block::init();
    for (int k = i; k <= j; k++) block::siz[a[k]]++;
    for (int k = 0; k < (int)(q); k++)
      if (qt[k] == 1) {
        if (ql[k] <= i && qr[k] >= j)
          block::dec(qx[k]);
        else
          for (int p = max(i, ql[k]); p <= min(j, qr[k]); p++)
            a[p] = block::dec1(a[p], qx[k]);
      } else {
        if (ql[k] <= i && qr[k] >= j)
          qans[k] += block::query(qx[k]);
        else
          for (int p = max(i, ql[k]); p <= min(j, qr[k]); p++)
            qans[k] += block::query1(a[p]) == qx[k];
      }
  }
  for (int i = 0; i < (int)(q); i++)
    if (qt[i] == 2) printf("%d\n", qans[i]);
  return 0;
}
