#include <bits/stdc++.h>
using namespace std;
const int blk = 300;
int n, m, a[100010], val[100010], tag[340], bel[100010], st[340], ed[340],
    siz[100010], h[340][100010], mx[340], fa[100010];
inline int getf(int x) { return x == fa[x] ? x : fa[x] = getf(fa[x]); }
inline void merge(int x, int y) {
  x = getf(x);
  y = getf(y);
  if (x == y) return;
  fa[x] = y;
  siz[y] += siz[x];
}
void build(int blk) {
  int l = st[blk], r = ed[blk];
  for (int i = l; i <= r; i++) a[i] = val[getf(i)], h[blk][a[i]] = 0;
  for (int i = l; i <= r; i++) {
    val[i] = a[i];
    fa[i] = i;
    siz[i] = 1;
    if (!h[blk][val[i]])
      h[blk][val[i]] = i;
    else
      merge(i, h[blk][val[i]]);
  }
  while (!h[blk][mx[blk]]) mx[blk]--;
}
void change(int p, int l, int r, int v) {
  int L = st[p], R = ed[p];
  for (int i = L; i <= R; i++)
    a[i] = val[getf(i)], fa[i] = i, siz[i] = 1, h[p][a[i]] = 0;
  for (int i = l; i <= r; i++)
    if (a[i] - tag[p] > v) a[i] -= v;
  for (int i = L; i <= R; i++) val[i] = a[i];
  build(p);
}
void modify(int l, int r, int x) {
  if (bel[l] == bel[r]) {
    change(bel[l], l, r, x);
  } else {
    change(bel[l], l, ed[bel[l]], x);
    for (int i = bel[l] + 1; i < bel[r]; i++) {
      if (x * 2 <= mx[i] - tag[i]) {
        for (int j = tag[i] + 1; j <= tag[i] + x; j++) {
          if (!h[i][j]) continue;
          if (!h[i][j + x])
            h[i][j + x] = h[i][j], val[h[i][j + x]] += x;
          else
            merge(h[i][j], h[i][j + x]);
          h[i][j] = 0;
        }
        tag[i] += x;
      } else {
        for (int j = tag[i] + x + 1; j <= mx[i]; j++) {
          if (!h[i][j]) continue;
          if (!h[i][j - x])
            h[i][j - x] = h[i][j], val[h[i][j - x]] -= x;
          else
            merge(h[i][j], h[i][j - x]);
          h[i][j] = 0;
        }
        while (!h[i][mx[i]]) mx[i]--;
      }
    }
    change(bel[r], st[bel[r]], r, x);
  }
}
int query(int l, int r, int x) {
  if (bel[l] == bel[r]) {
    int ret = 0;
    for (int i = l; i <= r; i++) ret += ((val[getf(i)] - tag[bel[l]]) == x);
    return ret;
  }
  int ret = 0;
  for (int i = l; i <= ed[bel[l]]; i++)
    ret += ((val[getf(i)] - tag[bel[l]]) == x);
  for (int i = bel[l] + 1; i < bel[r]; i++)
    if (x + tag[i] <= mx[i]) ret += siz[h[i][x + tag[i]]];
  for (int i = st[bel[r]]; i <= r; i++)
    ret += ((val[getf(i)] - tag[bel[r]]) == x);
  return ret;
}
void debug() {
  for (int i = 1; i <= bel[n]; i++) {
    printf("%d:", i);
    for (int j = st[i]; j <= ed[i]; j++)
      printf("%d:%d ", val[getf(j)], getf(j));
    puts("");
    for (int j = 1; j <= 10; j++) printf("%d:%d ", h[i][j], siz[h[i][j]]);
    printf("%d\n", tag[i]);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    fa[i] = i;
    val[i] = a[i];
    bel[i] = (i - 1) / blk + 1;
    mx[bel[i]] = max(mx[bel[i]], a[i]);
    if (bel[i] != bel[i - 1]) st[bel[i]] = i;
    ed[bel[i]] = i;
  }
  for (int i = 1; i <= bel[n]; i++) build(i);
  for (int i = 1, opt, l, r, x; i <= m; i++) {
    scanf("%d%d%d%d", &opt, &l, &r, &x);
    if (opt == 1)
      modify(l, r, x);
    else
      printf("%d\n", query(l, r, x));
  }
  return 0;
}
