#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")
const int maxn = 1e5 + 510, maxm = 1e6 + 10, lg = 21, mod = 1e9 + 7, inf = 1e18;
const int B = 320;
int n, q, a[maxn], L[maxn], R[maxn], X[maxn], ans[maxn], ty[maxn], P[maxn];
int l, r;
int gpar(int v) { return P[v] <= 0 ? v : P[v] = gpar(P[v]); }
void spar(int v, int u) {
  P[v] += P[u];
  P[u] = v;
}
void upd(int x) {
  if (l + x >= r) return;
  if (r - x <= x - l) {
    for (int i = l + x + 1; i < r; i++) spar(i - x, i);
    r = l + x + 1;
  } else {
    for (int i = l + 1; i <= l + x; i++) spar(i + x, i);
    l = l + x;
  }
}
void upd1(int i, int x) {
  a[i] = gpar(a[i]);
  if (a[i] - l <= x) return;
  P[a[i]]++;
  P[a[i] -= x]--;
}
int get(int x) { return (l + x >= r ? 0 : -P[l + x]); }
int get1(int k) { return gpar(a[k]) - l; }
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> q;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < q; i++) cin >> ty[i] >> L[i] >> R[i] >> X[i], L[i]--;
  for (int i = 0; i < n; i += B) {
    l = 0, r = maxn - 505;
    memset(P, 0, sizeof(P));
    for (int j = i; j < min(i + B, n); j++) P[a[j]]--;
    for (int j = 0; j < q; j++) {
      if (ty[j] == 1) {
        if (L[j] <= i && R[j] >= i + B)
          upd(X[j]);
        else
          for (int k = max(L[j], i); k < min(R[j], i + B); k++) upd1(k, X[j]);
      } else {
        if (L[j] <= i && R[j] >= i + B)
          ans[j] += get(X[j]);
        else
          for (int k = max(L[j], i); k < min(R[j], i + B); k++)
            ans[j] += (get1(k) == X[j]);
      }
    }
  }
  for (int i = 0; i < q; i++)
    if (ty[i] == 2) cout << ans[i] << '\n';
  return 0;
}
