#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
int a[101010];
int solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> a[i];
  while (m--) {
    int t, l, r, x;
    cin >> t >> l >> r >> x;
    --l;
    auto ap = a + l;
    r -= l;
    if (t == 1) {
      while (r % 4) {
        --r;
        ap[r] -= ap[r] > x ? x : 0;
      }
      r /= 4;
      while (r--) {
        ap[0] -= ap[0] > x ? x : 0;
        ap[1] -= ap[1] > x ? x : 0;
        ap[2] -= ap[2] > x ? x : 0;
        ap[3] -= ap[3] > x ? x : 0;
        ap += 4;
      }
    } else {
      int ans = 0;
      while (r % 4) {
        --r;
        ans += ap[r] == x;
      }
      r /= 4;
      while (r--) {
        ans += (ap[0] == x) + (ap[1] == x) + (ap[2] == x) + (ap[3] == x);
        ap += 4;
      }
      cout << ans << '\n';
    }
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  solve();
}
