#include <bits/stdc++.h>
using namespace std;
int n, m, k, a[200005], be[200005], l[200005], r[200005], tag[200005],
    fa[200005], las[355][200005], mx[200005], siz[200005], occ;
int get(int x) {
  if (fa[x] == x) return fa[x];
  return fa[x] = get(fa[x]);
}
void Break(int x) {
  for (int i = l[x]; i <= r[x]; i++) {
    a[i] = a[get(i)];
  }
  for (int i = l[x]; i <= r[x]; i++) {
    a[i] -= tag[x];
  }
  for (int i = l[x]; i <= r[x]; i++) {
    las[x][a[i]] = 0;
  }
  tag[x] = 0;
}
void build(int x) {
  mx[x] = 0;
  for (int i = l[x]; i <= r[x]; i++) {
    fa[i] = i;
    mx[x] = max(mx[x], a[i]);
    siz[i] = 1;
  }
  for (int i = l[x]; i <= r[x]; i++) {
    if (las[x][a[i]]) {
      siz[las[x][a[i]]]++;
      fa[i] = las[x][a[i]];
    } else
      las[x][a[i]] = i;
  }
}
void merge(int i, int x, int y) {
  if (!las[i][x])
    return;
  else if (!las[i][y]) {
    las[i][y] = las[i][x];
    las[i][x] = 0;
    a[las[i][y]] = y;
  } else {
    siz[get(las[i][y])] += siz[get(las[i][x])];
    fa[get(las[i][x])] = get(las[i][y]);
    las[i][x] = 0;
  }
}
void del(int L, int R, int x) {
  int bel = be[L], ber = be[R];
  if (bel == ber) {
    Break(bel);
    for (int i = L; i <= R; i++) {
      if (a[i] > x) a[i] -= x;
    }
    build(bel);
    return;
  }
  Break(bel);
  Break(ber);
  for (int i = L; i <= r[bel]; i++) {
    if (a[i] > x) a[i] -= x;
  }
  for (int i = l[ber]; i <= R; i++) {
    if (a[i] > x) a[i] -= x;
  }
  build(bel);
  build(ber);
  for (int i = bel + 1; i < ber; i++) {
    if (2 * x >= mx[i] - tag[i]) {
      for (int t = x + 1 + tag[i]; t <= mx[i]; t++) {
        merge(i, t, t - x);
      }
      mx[i] = min(mx[i], x);
    } else {
      for (int t = 1; t <= x; t++) {
        merge(i, t + tag[i], t + x + tag[i]);
      }
      tag[i] += x;
    }
  }
}
void que(int L, int R, int x) {
  int bel = be[L], ber = be[R], ans = 0;
  if (bel == ber) {
    for (int i = L; i <= R; i++) {
      if (a[i] == x) ans++;
    }
    printf("%d\n", ans);
    return;
  }
  for (int i = L; i <= r[bel]; i++)
    if (a[i] - tag[be[i]] == x) ans++;
  for (int i = l[ber]; i <= R; i++)
    if (a[i] - tag[be[i]] == x) ans++;
  for (int i = bel + 1; i < ber; i++) {
    ans += siz[get(las[i][x + tag[i]])];
  }
  printf("%d\n", ans);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  k = sqrt(n);
  for (int i = 1; i <= n; i += k) {
    occ++;
    l[occ] = i;
    r[occ] = min(i + k - 1, n);
    for (int t = l[occ]; t <= r[occ]; t++) {
      be[t] = occ;
    }
    build(occ);
  }
  for (int i = 1; i <= m; i++) {
    int op, l, r, x;
    scanf("%d%d%d%d", &op, &l, &r, &x);
    if (op == 1) {
      del(l, r, x);
    } else {
      que(l, r, x);
    }
  }
}
