#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 79, sqrtn = sqrt(maxn);
int s[maxn], p[maxn], a[maxn], undo[maxn], ans[maxn];
struct query {
  int typ, l, r, x;
} qu[maxn];
int n, q, changes = -1;
int root(int x) { return x == p[x] ? x : p[x] = root(p[x]); }
void merge(int x, int y) {
  s[x] += s[y], s[y] = 0;
  p[y] = x, undo[++changes] = y;
}
void reset_dsu() {
  while (changes >= 0) p[undo[changes]] = undo[changes], changes--;
}
void rebuild_block(int l, int r, int delta) {
  for (int i = l; i <= r; i++) {
    a[i] = root(a[i]);
    s[a[i]] = 0;
    a[i] -= delta;
  }
}
void set_block(int l, int r, int &delta, int &maxi) {
  maxi = delta = 0;
  for (int i = l; i <= r; i++) maxi = max(maxi, a[i]), s[a[i]]++;
}
void solve_block(int l, int r) {
  reset_dsu();
  int maxi = 0, delta = 0;
  for (int i = 0; i < maxn; i++) p[i] = i, s[i] = 0;
  set_block(l, r, delta, maxi);
  for (int i = 0; i < q; i++) {
    if (r < qu[i].l || l > qu[i].r) continue;
    if (qu[i].typ == 1) {
      if (maxi <= qu[i].x + delta) continue;
      if (qu[i].l <= l && r <= qu[i].r) {
        if (2 * qu[i].x <= maxi - delta) {
          for (int j = delta + 1; j <= delta + qu[i].x; j++)
            merge(j + qu[i].x, j);
          delta += qu[i].x;
        } else {
          for (int j = delta + qu[i].x + 1; j <= maxi; j++)
            merge(j - qu[i].x, j);
          maxi = delta + qu[i].x;
        }
      } else {
        rebuild_block(l, r, delta);
        for (int j = max(l, qu[i].l); j <= min(r, qu[i].r); j++)
          if (a[j] > qu[i].x) a[j] -= qu[i].x;
        reset_dsu(), set_block(l, r, delta, maxi);
      }
    } else {
      if (qu[i].l <= l && r <= qu[i].r)
        ans[i] += s[qu[i].x + delta];
      else {
        rebuild_block(l, r, delta);
        for (int j = max(l, qu[i].l); j <= min(r, qu[i].r); j++)
          ans[i] += (a[j] == qu[i].x);
        reset_dsu(), set_block(l, r, delta, maxi);
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> q;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < q; i++) {
    cin >> qu[i].typ >> qu[i].l >> qu[i].r >> qu[i].x;
    qu[i].l--, qu[i].r--;
  }
  for (int l = 0; l < n; l += sqrtn) solve_block(l, min(l + sqrtn - 1, n - 1));
  for (int i = 0; i < q; i++)
    if (qu[i].typ == 2) cout << ans[i] << "\n";
  return 0;
}
