#include <bits/stdc++.h>
using namespace std;
int B, n, m;
int li[500008], ri[500008], mx[500008], tag[500008];
short g[480][100008];
int bel[500008], de[500008], ai[500008], pa[500008];
short size[500008];
int find(int x) {
  if (pa[x] == x) return x;
  return pa[x] = find(pa[x]);
}
void link(int x, int y) {
  if (x == y) return;
  if (size[x] > size[y]) swap(x, y);
  pa[x] = y;
  size[y] += size[x];
}
int tot;
int lst[500008], stamp[500008];
void makeup(int id) {
  ++tot;
  mx[id] = 0;
  for (int i = li[id]; i <= ri[id]; i++) pa[i] = i, size[i] = 1;
  for (int i = li[id]; i <= ri[id]; i++) {
    int x = ai[i];
    mx[id] = max(mx[id], x);
    if (stamp[x] != tot)
      stamp[x] = tot, g[id][x] = lst[x] = i - li[id];
    else
      link(i, g[id][x] + li[id]), g[id][x] = find(g[id][x] + li[id]) - li[id];
  }
}
void pushdown(int id) {
  for (int i = li[id]; i <= ri[id]; i++) g[id][ai[i]] = -1;
  for (int i = li[id]; i <= ri[id]; i++) {
    g[id][ai[i] + de[i]] = -1;
    if (find(i) == i) ai[i] = ai[i] + de[i] - tag[id];
    de[i] = 0;
  }
  for (int i = li[id]; i <= ri[id]; i++) ai[i] = ai[find(i)];
  tag[id] = 0;
}
void refresh(int id) {
  while (-1 == g[id][mx[id]]) mx[id]--;
}
int cnt = 0;
void subtract(int id, int x) {
  if (mx[id] - tag[id] <= x) return;
  if (mx[id] - tag[id] > x * 2 + 1 and 1) {
    for (int i = tag[id] + 1; i <= x + tag[id]; i++)
      if (g[id][i] != -1) {
        int j = i + x;
        de[g[id][i] + li[id]] += x;
        if (g[id][j] != -1)
          link(g[id][i] + li[id], g[id][j] + li[id]),
              g[id][j] = find(g[id][j] + li[id]) - li[id];
        else
          g[id][j] = g[id][i];
        g[id][i] = -1;
      }
    tag[id] += x;
  } else {
    for (int i = x + 1 + tag[id]; i <= mx[id]; i++)
      if (g[id][i] != -1) {
        int j = i - x;
        de[g[id][i] + li[id]] -= x;
        if (g[id][j] != -1)
          link(g[id][j] + li[id], g[id][i] + li[id]),
              g[id][j] = find(g[id][j] + li[id]) - li[id];
        else
          g[id][j] = g[id][i];
        g[id][i] = -1;
      }
    refresh(id);
  }
}
int ask(int id, int x) {
  if (x + tag[id] > 100001) return 0;
  if (g[id][x + tag[id]] == -1) return 0;
  g[id][x + tag[id]] = find(g[id][x + tag[id]] + li[id]) - li[id];
  return size[g[id][x + tag[id]] + li[id]];
}
signed main() {
  memset(g, -1, sizeof g);
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &ai[i]);
  B = sqrt(n);
  B = max(B, n / 475);
  memset(li, 0x3f, sizeof li);
  for (int i = 1; i <= n; i++) {
    bel[i] = i / B;
    li[bel[i]] = min(li[bel[i]], i);
    ri[bel[i]] = i;
  }
  for (int i = 0; i <= n / B; i++) makeup(i);
  while (m--) {
    int op, l, r, x;
    scanf("%d%d%d%d", &op, &l, &r, &x);
    if (op == 1) {
      if (bel[l] == bel[r]) {
        pushdown(bel[l]);
        for (int i = l; i <= r; i++)
          if (ai[i] > x) ai[i] -= x;
        makeup(bel[l]);
      } else {
        pushdown(bel[l]);
        for (int i = l; i <= ri[bel[l]]; i++)
          if (ai[i] > x) ai[i] -= x;
        pushdown(bel[r]);
        for (int i = li[bel[r]]; i <= r; i++)
          if (ai[i] > x) ai[i] -= x;
        makeup(bel[l]);
        makeup(bel[r]);
        for (int i = bel[l] + 1; i < bel[r]; i++) subtract(i, x);
      }
    } else {
      int ans = 0;
      if (bel[l] == bel[r]) {
        pushdown(bel[l]);
        for (int i = l; i <= r; i++)
          if (ai[i] == x) ans++;
        makeup(bel[l]);
        printf("%d\n", ans);
      } else {
        pushdown(bel[l]);
        for (int i = l; i <= ri[bel[l]]; i++) ans += (ai[i] == x);
        pushdown(bel[r]);
        for (int i = li[bel[r]]; i <= r; i++) ans += (ai[i] == x);
        makeup(bel[l]);
        makeup(bel[r]);
        for (int i = bel[l] + 1; i < bel[r]; i++) ans += ask(i, x);
        printf("%d\n", ans);
      }
    }
    ++cnt;
    if (cnt < -7) {
      for (int i = 0; i <= n / B; i++) pushdown(i);
      for (int i = 1; i <= n; i++) cout << ai[i] << " ";
      cout << g[2][30] << ":\n\n";
      for (int i = 0; i <= n / B; i++) makeup(i);
    }
  }
  return 0;
}
