#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char x = '\0';
  int fh = 1, sum = 0;
  for (x = getchar(); x < '0' || x > '9'; x = getchar())
    if (x == '-') fh = -1;
  for (; x >= '0' && x <= '9'; x = getchar()) sum = sum * 10 + x - '0';
  return fh * sum;
}
const int N = 100009;
int n, m, ai[N];
struct node {
  int opt, l, r, x;
} q[N];
int ans[N];
int L[N], R[N], val[N], tot, siz;
int fa[N], rt[N], cnt[N], d[N];
int mx, tag, l, r, tmp, ql, qr, x;
inline int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
inline void merge(int x, int y) {
  if (rt[y])
    fa[rt[x]] = rt[y];
  else {
    rt[y] = rt[x];
    val[rt[y]] = y;
  }
  cnt[y] += cnt[x];
  rt[x] = cnt[x] = 0;
}
inline void build() {
  mx = tag = tot = 0;
  memset(rt, 0, sizeof(rt));
  memset(cnt, 0, sizeof(cnt));
  for (int i = l; i <= r; i++) {
    mx = max(mx, ai[i]);
    if (rt[ai[i]])
      fa[i] = rt[ai[i]];
    else {
      rt[ai[i]] = fa[i] = i;
      val[i] = ai[i];
    }
    cnt[ai[i]]++;
  }
}
inline void modi() {
  if ((x << 1) <= mx - tag) {
    for (int j = tag + 1; j <= tag + x; j++)
      if (rt[j]) merge(j, j + x);
    tag += x;
  } else {
    for (int j = mx; j > tag + x; j--)
      if (rt[j]) merge(j, j - x);
    if (tag + x < mx) mx = tag + x;
  }
}
inline void rebuild() {
  for (int j = l; j <= r; j++) {
    ai[j] = val[find(j)];
    rt[ai[j]] = cnt[ai[j]] = 0;
    ai[j] -= tag;
  }
  for (int j = l - 10; j <= r + 10; j++) val[j] = 0;
  tag = mx = tot = 0;
  tmp = min(qr, r);
  for (int j = max(ql, l); j <= tmp; j++) {
    ai[j] = ai[j] > x ? ai[j] - x : ai[j];
  }
  for (int j = l; j <= r; j++) {
    mx = max(mx, ai[j]);
    if (rt[ai[j]])
      fa[j] = rt[ai[j]];
    else {
      rt[ai[j]] = fa[j] = j;
      val[j] = ai[j];
    }
    cnt[ai[j]]++;
  }
}
inline void get(int i) {
  if (x + tag > 500000) return;
  if (ql <= l && r <= qr)
    ans[i] += cnt[x + tag];
  else {
    tmp = min(r, qr);
    for (int j = max(l, ql); j <= tmp; j++)
      if (val[find(j)] == tag + x) ans[i]++;
  }
}
int main() {
  n = read(), m = read();
  siz = sqrt(n - 1) + 1;
  for (int i = 1; i <= n; i++) ai[i] = read();
  for (int i = 1; i <= m; i++) {
    q[i].opt = read();
    q[i].l = read();
    q[i].r = read();
    q[i].x = read();
  }
  int ge = 1;
  L[1] = 1;
  while (L[ge] + siz < n) {
    R[ge] = L[ge] + siz - 1;
    ge++;
    L[ge] = R[ge - 1] + 1;
  }
  R[ge] = n;
  for (int now = 1; now <= ge; now++) {
    l = L[now], r = R[now];
    build();
    for (int i = 1; i <= m; i++) {
      ql = q[i].l, qr = q[i].r, x = q[i].x;
      if (r < ql || qr < l) continue;
      if (q[i].opt == 1) {
        if (ql <= l && r <= qr)
          modi();
        else
          rebuild();
      } else
        get(i);
    }
  }
  for (int i = 1; i <= m; i++)
    if (q[i].opt == 2) printf("%d\n", ans[i]);
  return 0;
}
