#include <bits/stdc++.h>
using namespace std;
int a[100005], fa[100005], fst[320][100005], lb[320], rb[320], bl[100005],
    maxx[320], tag[320], cnt[100005];
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
void build(int n) {
  maxx[n] = 0;
  for (int i = lb[n]; i <= rb[n]; i++) {
    if (!fst[n][a[i]])
      fst[n][a[i]] = i, fa[i] = i, cnt[fst[n][a[i]]] = 1;
    else
      fa[i] = fst[n][a[i]], cnt[fst[n][a[i]]]++;
    maxx[n] = max(maxx[n], a[i]);
  }
}
void down(int x) {
  for (int i = lb[x]; i <= rb[x]; i++)
    a[i] = a[find(i)], cnt[fst[x][a[i]]] = 0, fst[x][a[i]] = 0;
  for (int i = lb[x]; i <= rb[x]; i++) a[i] -= tag[x], fa[i] = 0;
  tag[x] = 0;
}
void upd(int l, int r, int x) {
  for (int i = bl[l]; i <= bl[r]; i++) down(i);
  for (int i = l; i <= r; i++)
    if (a[i] > x) a[i] -= x;
  for (int i = bl[l]; i <= bl[r]; i++) build(i);
}
void chg(int x, int y, int z) {
  if (!fst[x][y]) return;
  if (!fst[x][z])
    a[fst[x][z] = fst[x][y]] = z;
  else
    fa[fst[x][y]] = fst[x][z], cnt[fst[x][z]] += cnt[fst[x][y]];
  fst[x][y] = 0;
}
void updblk(int x, int v) {
  if (v >= maxx[x] - tag[x]) return;
  if (v << 2 > maxx[x] - tag[x]) {
    for (int i = tag[x] + v + 1; i <= maxx[x]; i++) chg(x, i, i - v);
    maxx[x] = max(maxx[x] - v, v + tag[x]);
  } else {
    for (int i = tag[x] + 1; i <= tag[x] + v; i++) chg(x, i, i + v);
    tag[x] += v;
  }
}
void update(int l, int r, int v) {
  if (bl[l] >= bl[r] - 1) {
    upd(l, r, v);
    return;
  }
  upd(l, rb[bl[l]], v);
  upd(lb[bl[r]], r, v);
  for (int i = bl[l] + 1; i < bl[r]; i++) updblk(i, v);
}
int qry(int l, int r, int v) {
  int ans = 0;
  for (int i = l; i <= r; i++) {
    if (a[find(i)] - tag[bl[i]] == v) ans++;
  }
  return ans;
}
int qryblk(int x, int v) {
  if (v + tag[x] > 100000) return 0;
  return cnt[fst[x][v + tag[x]]];
}
int query(int l, int r, int v) {
  if (bl[l] + 1 >= bl[r]) return qry(l, r, v);
  int ans = qry(l, rb[bl[l]], v) + qry(lb[bl[r]], r, v);
  for (int i = bl[l] + 1; i < bl[r]; i++) ans += qryblk(i, v);
  return ans;
}
int main() {
  int n, m;
  cin >> n >> m;
  int len = int(sqrt(n) + 0.5);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    bl[i] = (i - 1) / len + 1;
    if (!lb[bl[i]]) lb[bl[i]] = i;
    rb[bl[i]] = i;
  }
  for (int i = 1; i <= bl[n]; i++) build(i);
  for (int i = 1; i <= m; i++) {
    int opt, l, r, v;
    cin >> opt >> l >> r >> v;
    switch (opt) {
      case 1: {
        update(l, r, v);
        break;
      }
      case 2: {
        cout << query(l, r, v) << endl;
        break;
      }
    }
  }
  return 0;
}
