#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx2,sse2")
using namespace std;
template <typename Container>
void print(Container& container) {
  auto Start = container.begin(), End = container.end();
  while (Start != End) cout << *(Start++) << " ";
  cout << '\n';
}
int n, m, a[100005];
inline void solve() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 0; i < m; ++i) {
    int t, l, r, x;
    cin >> t >> l >> r >> x;
    if (t == 1)
      for (int j = l; j <= r; ++j) a[j] -= (a[j] > x ? x : 0);
    else {
      int ans = 0;
      for (int j = l; j <= r; ++j) ans += (a[j] == x);
      cout << ans << '\n';
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int t = 1;
  while (t--) solve();
}
