#include <bits/stdc++.h>
using namespace std;
inline void rd(int &x) {
  x = 0;
  char ch = 0;
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
}
int n, m, B;
int rt[320][100005];
int L[320], R[320], mx[320];
int a[100005], b[100005], c[100005], f[100005], sz[100005];
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
void push(int x) {
  for (int i = L[x]; i <= R[x]; i++) a[i] = b[find(i)], rt[x][a[i]] = 0;
  for (int i = L[x]; i <= R[x]; i++) f[i] = 0;
}
void init(int x) {
  mx[x] = 0;
  for (int i = L[x]; i <= R[x]; i++) {
    sz[i] = 1;
    mx[x] = max(mx[x], a[i]);
    if (rt[x][a[i]])
      f[i] = rt[x][a[i]], sz[f[i]]++;
    else
      b[i] = a[i], f[i] = i, rt[x][a[i]] = i;
  }
}
void merge(int now, int &x, int &y, int val) {
  x ? (f[y] = x, sz[x] += sz[y]) : (x = y, b[x] = val);
}
void change(int now, int x) {
  for (int i = x + 1; i <= mx[now]; i++)
    if (b[rt[now][i]] == i) merge(now, rt[now][i - x], rt[now][i], i - x);
  if (mx[now] >= x) mx[now] -= x;
}
void change(int l, int r, int x) {
  if (c[l] == c[r]) {
    push(c[l]);
    for (int i = l; i <= r; i++)
      if (a[i] > x) a[i] -= x;
    init(c[l]);
    return;
  }
  push(c[l]);
  push(c[r]);
  for (int i = l; i <= R[c[l]]; i++)
    if (a[i] > x) a[i] -= x;
  for (int i = L[c[r]]; i <= r; i++)
    if (a[i] > x) a[i] -= x;
  for (int i = c[l] + 1; i < c[r]; i++) change(i, x);
  init(c[l]);
  init(c[r]);
}
int ask(int l, int r, int x, int ans = 0) {
  if (c[l] == c[r]) {
    for (int i = l; i <= r; i++) ans += b[find(i)] == x;
    return ans;
  }
  for (int i = l; i <= R[c[l]]; i++) ans += b[find(i)] == x;
  for (int i = L[c[r]]; i <= r; i++) ans += b[find(i)] == x;
  for (int i = c[l] + 1; i < c[r]; i++) ans += sz[rt[i][x]];
  return ans;
}
void init() {
  for (int i = 1; i <= n; i++) c[i] = (i - 1) / B + 1;
  for (int i = 1; i <= c[n]; init(i), i++)
    L[i] = (i - 1) * B + 1, R[i] = min(n, L[i] + B - 1);
}
signed main() {
  rd(n);
  rd(m);
  B = sqrt(n);
  for (int i = 1; i <= n; i++) rd(a[i]);
  init();
  while (m--) {
    int pd, l, r, x;
    rd(pd), rd(l), rd(r), rd(x);
    if (pd == 1) change(l, r, x);
    if (pd == 2) printf("%d\n", ask(l, r, x));
  }
}
