#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx")
using namespace std;
float a[100010];
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    int v;
    cin >> v;
    a[i] = v;
  }
  while (m--) {
    int tp, L, R, x;
    cin >> tp >> L >> R >> x;
    float v = x;
    if (tp == 1) {
      for (int i = L; i <= R; i++) {
        if (a[i] > x) a[i] -= x;
      }
    } else {
      int ans = 0;
      for (int i = L; i <= R; i++) {
        if (a[i] == x) ans++;
      }
      cout << ans << endl;
    }
  }
}
