#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
const int B = 250;
int n, m, cnt, ans;
int sm[405], head[405], tag[405], bt[405][maxn], p[405], v[405], s[405][maxn];
int nxt[maxn], siz[maxn], val[maxn], fs[maxn], ls[maxn];
int pv[maxn], nx[maxn];
queue<int> q;
inline void rebuild(int a, int b, int x, int i) {
  int j, k, u, last;
  for (last = cnt = 0, j = head[i]; j; j = nxt[j]) {
    s[i][val[j]] = 0, val[j] -= tag[i];
    if (val[j] > x)
      for (k = fs[j]; ~k; k = nx[k])
        if (k >= a && k <= b) {
          p[++cnt] = k, v[cnt] = val[j] - x, siz[j]--;
          if (pv[k] == -1)
            fs[j] = nx[k];
          else
            nx[pv[k]] = nx[k];
          if (nx[k] == -1)
            ls[j] = pv[k];
          else
            pv[nx[k]] = pv[k];
        }
    if (!siz[j]) {
      q.push(j);
      if (!last)
        head[i] = nxt[j];
      else
        nxt[last] = nxt[j];
    } else
      last = j;
  }
  tag[i] = 0;
  for (last = 0, k = 1, j = head[i]; k <= cnt; k++) {
    for (; j && val[j] <= v[k]; last = j, j = nxt[j])
      ;
    if (last && v[k] == val[last])
      u = p[k], pv[u] = ls[last], nx[u] = -1, nx[ls[last]] = u, ls[last] = u,
      siz[last]++;
    else {
      u = q.front(), q.pop(), val[u] = v[k], fs[u] = ls[u] = p[k],
      pv[p[k]] = nx[p[k]] = -1, siz[u] = 1;
      if (!last)
        nxt[u] = head[i], head[i] = u;
      else
        nxt[u] = nxt[last], nxt[last] = u;
      last = u;
    }
  }
  for (j = head[i]; j; j = nxt[j]) s[i][val[j]] += siz[j], sm[i] = val[j];
}
inline void updata(int x, int i) {
  if (sm[i] <= x) return;
  int j, k, u, last;
  for (cnt = 0, j = head[i]; j && val[j] - tag[i] <= x; j = nxt[j])
    p[++cnt] = j;
  head[i] = j;
  if (x + x <= sm[i])
    for (tag[i] += x, k = 1; k <= cnt; k++)
      u = p[k], s[i][val[u]] -= siz[u], val[p[k]] += x, s[i][val[u]] += siz[u];
  else
    for (sm[i] = val[p[cnt]], j = head[i]; j;
         sm[i] = max(sm[i], val[j]), j = nxt[j])
      s[i][val[j]] -= siz[j], val[j] -= x, s[i][val[j]] += siz[j];
  for (last = 0, k = 1, j = head[i]; k <= cnt; k++) {
    for (u = p[k]; j && val[j] <= val[u]; last = j, j = nxt[j])
      ;
    if (last && val[u] == val[last])
      pv[fs[u]] = ls[last], nx[ls[last]] = fs[u], ls[last] = ls[u],
      siz[last] += siz[u], q.push(u);
    else {
      if (!last)
        nxt[u] = head[i], head[i] = u;
      else
        nxt[u] = nxt[last], nxt[last] = u;
      last = u;
    }
  }
}
inline int rd() {
  int ret = 0, f = 1;
  char gc = getchar();
  while (gc < '0' || gc > '9') {
    if (gc == '-') f = -f;
    gc = getchar();
  }
  while (gc >= '0' && gc <= '9') ret = ret * 10 + (gc ^ '0'), gc = getchar();
  return ret * f;
}
int main() {
  n = rd(), m = rd();
  int i, j, k, last, a, b, c, d, x;
  memset(fs, -1, sizeof(fs)), memset(ls, -1, sizeof(ls)),
      memset(pv, -1, sizeof(pv)), memset(nx, -1, sizeof(nx));
  for (i = 1; i <= n; i++) q.push(i);
  for (i = 0; i < n; i++) {
    a = rd(), sm[i / B] = max(sm[i / B], a), s[i / B][a]++;
    if (!bt[i / B][a])
      b = bt[i / B][a] = q.front(), q.pop(), fs[b] = ls[b] = i, val[b] = a,
      siz[b] = 1;
    else
      b = bt[i / B][a], nx[ls[b]] = i, pv[i] = ls[b], ls[b] = i, siz[b]++;
  }
  for (i = 0; i * B < n; i++) {
    for (last = 0, j = 1; j <= sm[i]; j++)
      if (bt[i][j]) {
        if (last)
          nxt[last] = bt[i][j];
        else
          head[i] = bt[i][j];
        last = bt[i][j];
      }
  }
  for (i = 0; i < m; i++) {
    if (rd() == 1) {
      a = rd() - 1, b = rd() - 1, c = a / B, d = b / B, x = rd();
      if (c == d)
        rebuild(a, b, x, c);
      else {
        rebuild(a, b, x, c), rebuild(a, b, x, d);
        for (j = c + 1; j < d; j++) updata(x, j);
      }
    } else {
      a = rd() - 1, b = rd() - 1, c = a / B, d = b / B, x = rd(), ans = 0;
      if (c == d) {
        for (j = head[c]; j; j = nxt[j])
          if (val[j] - tag[c] == x)
            for (k = fs[j]; ~k; k = nx[k])
              if (k >= a && k <= b) ans++;
      } else {
        for (j = head[c]; j; j = nxt[j])
          if (val[j] - tag[c] == x)
            for (k = fs[j]; ~k; k = nx[k])
              if (k >= a && k <= b) ans++;
        for (j = head[d]; j; j = nxt[j])
          if (val[j] - tag[d] == x)
            for (k = fs[j]; ~k; k = nx[k])
              if (k >= a && k <= b) ans++;
        for (j = c + 1; j < d; j++)
          if (x + tag[j] <= sm[j]) ans += s[j][x + tag[j]];
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
