#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
using namespace std;
const int N = 100005;
int n, m, a[N], l, r, opt, x;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  while (m--) {
    scanf("%d%d%d%d", &opt, &l, &r, &x);
    if (opt == 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++;
      printf("%d\n", ans);
    }
  }
}
