#include <bits/stdc++.h>
using namespace std;
int BLK, a[100001], resp[400], par[400][100001], RMAX[400], LMAX[400],
    f[400][100001], L[400], R[400];
int find(int bi, int x) {
  return (!par[bi][x] || par[bi][x] == x) ? par[bi][x] = x
                                          : par[bi][x] = find(bi, par[bi][x]);
}
void updater(int bi, int l, int r, int x) {
  for (int i = l; i <= r; i++) {
    a[i] = find(bi, a[i]);
    if (a[i] > resp[bi] + x) {
      f[bi][a[i]]--;
      a[i] -= x;
      f[bi][a[i]]++;
    }
  }
}
void updateblk(int bi, int x) {
  if (RMAX[bi] - LMAX[bi] <= x) return;
  if (RMAX[bi] - LMAX[bi] <= 2 * x) {
    for (int i = LMAX[bi] + x + 1; i <= RMAX[bi]; i++) {
      par[bi][i] = i - x;
      f[bi][i - x] += f[bi][i];
      f[bi][i] = 0;
    }
    RMAX[bi] = LMAX[bi] + x;
  } else {
    for (int i = LMAX[bi]; i <= LMAX[bi] + x; i++) {
      par[bi][i] = i + x;
      f[bi][i + x] += f[bi][i];
      f[bi][i] = 0;
    }
    LMAX[bi] += x;
    resp[bi] += x;
  }
}
int queryr(int bi, int l, int r, int x) {
  int res = 0;
  for (int i = l; i <= r; i++) {
    a[i] = find(bi, a[i]);
    res += (a[i] == resp[bi] + x);
  }
  return res;
}
int queryblk(int bi, int x) {
  if (RMAX[bi] - LMAX[bi] < x) return 0;
  return f[bi][x + resp[bi]];
}
int main() {
  int n, m, ans, x, op, l, r;
  scanf("%d%d", &n, &m);
  BLK = ceil(sqrt(n));
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]), f[(i - 1) / BLK][a[i]]++,
        RMAX[(i - 1) / BLK] = max(RMAX[(i - 1) / BLK], a[i]);
  for (int i = 0; i <= (n - 1) / BLK; i++)
    L[i] = i * BLK + 1, R[i] = (i + 1) * BLK;
  while (m--) {
    scanf("%d%d%d%d", &op, &l, &r, &x);
    if (op == 1) {
      if ((l - 1) / BLK == (r - 1) / BLK)
        updater((l - 1) / BLK, l, r, x);
      else {
        updater((l - 1) / BLK, l, R[(l - 1) / BLK], x);
        for (int i = (l - 1) / BLK + 1; i <= (r - 1) / BLK - 1; i++)
          updateblk(i, x);
        updater((r - 1) / BLK, L[(r - 1) / BLK], r, x);
      }
    } else {
      ans = 0;
      if ((l - 1) / BLK == (r - 1) / BLK)
        ans += queryr((l - 1) / BLK, l, r, x);
      else {
        ans += queryr((l - 1) / BLK, l, R[(l - 1) / BLK], x);
        for (int i = (l - 1) / BLK + 1; i <= (r - 1) / BLK - 1; i++)
          ans += queryblk(i, x);
        ans += queryr((r - 1) / BLK, L[(r - 1) / BLK], r, x);
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
