#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 5;
const int bsize = 340;
struct block {
  int d[maxn], p[maxn], tot, l, r;
  void add(int x) {
    d[x]++;
    r = max(x, r);
    if (l == 0 || l > x) l = x;
  }
  void del(int x) {
    if (--d[x] == 0) p[x] = 0;
  }
  int ff(int x) {
    if (p[x] == 0) p[x] = x;
    if (p[x] != x) p[x] = ff(p[x]);
    return p[x];
  }
  void update(int x) {
    int mid = (l + r) >> 1;
    if (x <= mid + tot) {
      for (int i = l; i < x - tot; i++) {
        if (d[i]) {
          d[i + x] += d[i];
          d[i] = 0;
          p[i] = i + x;
        }
      }
      l = x - tot;
      tot -= x;
    } else {
      for (int i = x + 1 - tot; i <= r; i++) {
        if (d[i]) {
          d[i - x] += d[i];
          d[i] = 0;
          p[i] = i - x;
        }
      }
      r = x - tot;
    }
  }
  int query(int x) {
    if (x - tot < l || x - tot > r)
      return 0;
    else
      return d[x - tot];
  }
} f[bsize];
int a[maxn], id[maxn], n;
void rebuild(int k, int l, int r, int x) {
  for (int i = k * bsize + 1; i <= min((k + 1) * bsize, n); i++) {
    a[i] = f[k].ff(a[i]);
    f[k].del(a[i]);
    a[i] += f[k].tot;
    if (l <= i && i <= r && a[i] > x) a[i] -= x;
  }
  f[k].l = f[k].r = f[k].tot = 0;
  for (int i = k * bsize + 1; i <= min((k + 1) * bsize, n); i++) f[k].add(a[i]);
}
int query(int k, int l, int r, int x) {
  int t = 0;
  for (int i = l; i <= r; i++) {
    if (f[k].ff(a[i]) + f[k].tot == x) t++;
  }
  return t;
}
int main() {
  int m, i, j, k, op, l, r, x;
  scanf("%d%d", &n, &m);
  for (i = 1, j = k = 0; i <= n; i++) {
    scanf("%d", &a[i]);
    id[i] = k;
    f[k].add(a[i]);
    if (++j == bsize) {
      j = 0;
      k++;
    }
  }
  while (m--) {
    scanf("%d%d%d%d", &op, &l, &r, &x);
    if (op == 1) {
      if (id[l] == id[r])
        rebuild(id[l], l, r, x);
      else {
        rebuild(id[l], l, r, x);
        rebuild(id[r], l, r, x);
        for (i = id[l] + 1; i < id[r]; i++) f[i].update(x);
      }
    } else {
      if (id[l] == id[r])
        k = query(id[l], l, r, x);
      else {
        k = query(id[l], l, (id[l] + 1) * bsize, x);
        k += query(id[r], id[r] * bsize + 1, r, x);
        for (i = id[l] + 1; i < id[r]; i++) k += f[i].query(x);
      }
      printf("%d\n", k);
    }
  }
  return 0;
}
