#include <bits/stdc++.h>
using namespace std;
char G[1 << 24], H[1 << 24], *z = G, *h = H;
inline int read() {
  int x = 0;
  while (*z < 48 || *z > 57) z++;
  while (*z > 47 && *z < 58) x = (x << 1) + (x << 3) + (*z++ ^ 48);
  return x;
}
void print(int x) {
  if (x / 10) print(x / 10);
  *h++ = x % 10 + 48;
}
int a[320], e[100005], f[320], g[100005], i, j, l, m, n, o[100005], p[100005],
    r, s[100005], t, u[100005], v[100005], w[100005], x, y;
int find(int x) { return x == f[x] ? x : find(f[x]); }
inline void del() {
  for (j = 1; j <= l; j++) e[a[j] = a[find(j)]] = 0, g[a[j]] = 0;
}
inline void add() {
  for (x = 0, j = 1; j <= l; x = max(x, a[j]), g[a[j]]++, f[j] = e[a[j]], j++)
    if (!e[a[j] -= y]) e[a[j]] = j;
  y = 0;
}
inline void change() {
  if (u[i] > t || v[i] < 1) return;
  if (p[i] > x - y) return;
  if (u[i] <= 1 && v[i] >= l) {
    if (x - y <= p[i] << 1) {
      for (j = p[i] + y + 1; j <= x; j++)
        if (e[j - p[i]])
          g[j - p[i]] += g[j], f[e[j]] = e[j - p[i]], e[j] = g[j] = 0;
        else
          a[e[j - p[i]] = e[j]] -= p[i], g[j - p[i]] = g[j], e[j] = g[j] = 0;
      x = p[i] + y;
    } else {
      for (j = y + 1; j <= p[i] + y; j++)
        if (e[j + p[i]])
          g[j + p[i]] += g[j], f[e[j]] = e[j + p[i]], e[j] = g[j] = 0;
        else
          a[e[j + p[i]] = e[j]] += p[i], g[j + p[i]] = g[j], e[j] = g[j] = 0;
      x = max(x, p[i] + y + p[i]), y += p[i];
    }
  } else {
    del();
    for (j = max(1, u[i]); j <= min(l, v[i]); j++)
      if (a[j] - y > p[i]) a[j] -= p[i];
    add();
  }
}
inline int get() {
  if (u[i] > t || v[i] < 1) return 0;
  if (u[i] <= 1 && v[i] >= l) {
    if (y + p[i] < 100005)
      return g[y + p[i]];
    else
      return 0;
  } else {
    int z = 0;
    for (j = max(1, u[i]); j <= min(l, v[i]); j++)
      if (a[find(j)] - y == p[i]) z++;
    return z;
  }
}
int main() {
  fread(G, 1, 1 << 24, stdin);
  n = read(), m = read(), t = sqrt(n);
  for (i = 1; i <= n; i++) s[i] = read();
  for (i = 1; i <= m; i++)
    o[i] = read(), u[i] = read(), v[i] = read(), p[i] = read();
  while (r < n) {
    while (l < t && r < n) a[++l] = s[++r];
    for (y = 0, add(), i = 1; i <= m; u[i] -= t, v[i] -= t, i++)
      if (o[i] == 1)
        change();
      else
        w[i] += get();
    del(), l = 0;
  }
  for (i = 1; i <= m; i++)
    if (o[i] == 2) print(w[i]), *h++ = '\n';
  fwrite(H, h - H, 1, stdout);
  return 0;
}
