#include <bits/stdc++.h>
int n, m, a[100010], block, pos[100010], start[100010];
int f[330][330], head[330][100010], mx[100010], cnt[100010], g[330][100010],
    v[330][330];
int find(int x, int *f) { return f[x] ? f[x] = find(f[x], f) : x; }
void Delete(int x) {
  for (int i = start[x] + 1; pos[i] == x; i++)
    a[i] = v[x][find(i - start[x], f[x])],
    head[x][a[i]] = g[x][head[x][a[i]]] = 0;
  memset(f[x], 0, sizeof f[x]);
}
void rebuild(int x) {
  mx[x] = 0;
  for (int i = start[x] + 1; pos[i] == x; i++) {
    if (!head[x][a[i]])
      head[x][a[i]] = i - start[x], v[x][head[x][a[i]]] = a[i];
    else
      f[x][i - start[x]] = head[x][a[i]];
    ++g[x][head[x][a[i]]];
    mx[x] = std::max(mx[x], a[i]);
  }
}
void change(int x, int i, int v) {
  if (head[x][i]) {
    if (!head[x][i + v]) {
      head[x][i + v] = head[x][i];
      head[x][i] = 0;
      ::v[x][head[x][i + v]] = i + v;
    } else {
      g[x][head[x][i + v]] += g[x][head[x][i]];
      g[x][head[x][i]] = 0;
      f[x][head[x][i]] = head[x][i + v];
      head[x][i] = 0;
    }
  }
}
void solve(int x, int v) {
  if (mx[x] - cnt[x] - v > v) {
    for (int i = 1 + cnt[x]; i <= v + cnt[x]; i++) change(x, i, v);
    cnt[x] += v;
  } else {
    for (int i = v + 1 + cnt[x]; i <= mx[x]; i++) change(x, i, -v);
    mx[x] = std::min(mx[x], cnt[x] + v);
  }
  while (!head[x][mx[x]]) --mx[x];
}
int main() {
  scanf("%d%d", &n, &m);
  block = (int)pow(n, 0.5);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  memset(start, -1, sizeof start);
  for (int i = 1; i <= n; i++) {
    pos[i] = (i - 1) / block + 1;
    if (!~start[pos[i]]) start[pos[i]] = i - 1;
  }
  for (int i = 1; i <= pos[n]; i++) rebuild(i);
  for (int i = 1, op, l, r, x; i <= m; i++) {
    scanf("%d%d%d%d", &op, &l, &r, &x);
    if (op == 1) {
      if (pos[l] == pos[r]) {
        Delete(pos[l]);
        for (int j = l; j <= r; j++)
          if (a[j] - cnt[pos[l]] > x) a[j] -= x;
        rebuild(pos[l]);
      } else {
        Delete(pos[l]);
        for (int j = l; pos[j] == pos[l]; j++)
          if (a[j] - cnt[pos[l]] > x) a[j] -= x;
        rebuild(pos[l]);
        Delete(pos[r]);
        for (int j = r; pos[j] == pos[r]; j--)
          if (a[j] - cnt[pos[r]] > x) a[j] -= x;
        rebuild(pos[r]);
        for (int j = pos[l] + 1; j < pos[r]; j++) solve(j, x);
      }
    } else {
      int ans = 0;
      if (pos[l] == pos[r]) {
        for (int j = l; j <= r; j++)
          ans += (v[pos[l]][find(j - start[pos[l]], f[pos[l]])] - cnt[pos[l]] ==
                  x);
      } else {
        for (int j = l; pos[j] == pos[l]; j++)
          ans += (v[pos[l]][find(j - start[pos[l]], f[pos[l]])] - cnt[pos[l]] ==
                  x);
        for (int j = r; pos[j] == pos[r]; j--)
          ans += (v[pos[r]][find(j - start[pos[r]], f[pos[r]])] - cnt[pos[r]] ==
                  x);
        for (int j = pos[l] + 1; j < pos[r]; j++)
          ans += g[j][head[j][x + cnt[j]]];
      }
      printf("%d\n", ans);
    }
  }
}
